我想弄一个网站用户登录的JSP程序,但是存在问题却始终无法解决,下面是我编的一段代码,还望各位高手们为我指点迷津。
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" import="javax.servlet.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<%String driver="sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver).newInstance();
String connectionURL="jdbc:odbc:EnterpriseDatabaseInformation";
Connection conn=null;
conn=DriverManager.getConnection(connectionURL);
Statement stmt=null;
stmt=conn.createStatement();
String username=request.getParameter("useName");
String password=request.getParameter("Password");
//输入为空,重导回这个页面
if(usename.equal("")||password.length()==0){
String redirectURL="edi.html";
response.sendRedirect(response.encodeURL(redirectURL));}
else{String sqlstring="SELECT * FROM users";sqlstring+="";sqlstring+="WHERE UserID LIKE '"+username"'";
ResultSet rs=null;
rs=stmt.executeQuery(sqlstring);
if(rs.next()){
if(rs.getString(2).equals(password)){
rs.close();
stmt.close();
conn.close();}
//如果数据库中存在该用户名,并且密码正确,重导至首页
String redirectURL="edi.html";
response.sendRedirect(response.encodeURL(redirectURL));
}
else{
rs.close();
stmt.close();
conn.close();
//存在该用户名,但密码不正确,重导回登录页面
String redirectURL="edi.html";
response.sendRedirect(response.encodeURL(redirectURL));
}
}
else{
rs.close();
stmt.close();
conn.close();
//不存在该用户名,重导回注册页面
String redirectURL="edi.html";
response.sendRedirect(response.encodeURL(redirectURL));}
}
%>
</body>
</html>