当前位置: 代码迷 >> Java Web开发 >> jsp登陆验证模块出现错误
  详细解决方案

jsp登陆验证模块出现错误

热度:151   发布时间:2016-04-16 22:18:49.0
jsp登陆验证模块出现异常
org.apache.jasper.JasperException: An exception occurred processing JSP page /logincheck.jsp at line 26

23:    ResultSet rs=null;
24:    String sqlstring = "select * from chatuser where username='"+ regName +"' and password='"+ regPassword + "'";
25:    rs = sqlbean.executeQuery(sqlstring);
26:    if(rs.next())
27:    {
28: 
29:      String experience=rs.getString("experience");

logincheck.jsp
<%@page contentType="text/html;charset=GBK"%>
<%@page import="java.util.*"%>
<%@ page import="java.sql.*" %>
<jsp:useBean id="sqlbean" scope="page" class="database.sqlbean">
</jsp:useBean>
<html>
<head>
<title>登录检查</title>
</head>
<body>

<%

String userType = request.getParameter("userType");


String regName=request.getParameter("username").trim();
String regPassword=request.getParameter("password").trim();
session.setAttribute("originname",regName);

 if (userType.equals("Y"))
 {
   ResultSet rs=null;
   String sqlstring = "select * from chatuser where username='"+ regName +"' and password='"+ regPassword + "'";
   rs = sqlbean.executeQuery(sqlstring);
   if(rs.next())
   {

     String experience=rs.getString("experience");
     String userlevel=rs.getString("userlevel");
     session.setAttribute("experience",experience);
     session.setAttribute("userlevel",userlevel);

       regName = regName + "[会员]";

     session.setAttribute("username",regName);

     rs.close();
     sqlbean.freeRs(rs);
     response.sendRedirect ("chat.jsp");
   }
   else
   {
     rs.close();
     out.print("<script>alert(\"用户名/密码错误!\");");
     out.print("window.location = \"login.jsp\"</script>");
   }
 }
 else
 {
if((regName.length()<1)||(regName.length()>10)) {
out.print("<script>alert(\"游客名不能超过6个字长!\");window.close();</script>");
return;
}

Character c=new Character(' ');
for(int i=0;i<regName.length();i++) {
if(regName.charAt(i) == c.charValue()) {
out.print("<script>alert(\"名字中间不能有空格!\");window.close();</script>");
return;
}
}
       regName = regName + "[非会员]";
 }

 synchronized (application)
   {
Vector UserName=null;
UserName= (Vector)application.getAttribute("UserName");
if(UserName==null) {
UserName= new Vector(30,10);
}

if(UserName.contains(regName)) {
out.print("<script>alert(\"你的名字正在被人使用!\");window.close();</script>");
return;
}

if(regName!=null ) {
            UserName.addElement(regName);
            session.setAttribute("username", regName);
}


application.setAttribute("UserName",UserName);
out.print("<script>window.location=\"chat.jsp\"</script>");
   }
%>
</body>
</html>


sqlbean.java
package database;
import java.sql.*;
import sun.io.*;

public class sqlbean{
private Connection con;
private ResultSet rs;

public static Connection getConnection() throws SQLException{
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ClassNotFoundException ex){
ex.printStackTrace();
return null;
}
return DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=chatdb","sa","");
}

public ResultSet executeQuery(String sql){
try{
con=sqlbean.getConnection();
Statement statement=con.createStatement();
rs=statement.executeQuery(sql);
}
catch(SQLException ex)
{
}
return rs;
}
public int executeUpdate(String sql)
{
int count=0;
Statement stmt=null;
try
{
con=sqlbean.getConnection();
stmt=con.createStatement();
count=stmt.executeUpdate(sql);
}
catch(SQLException ex)
{
}
finally
{
try
{
if(stmt !=null)
stmt.close();
if(con !=null)
con.close();
}
catch(SQLException ex)
  相关解决方案