当前位置: 代码迷 >> Java Web开发 >> [求助]用户登录代码纠错
  详细解决方案

[求助]用户登录代码纠错

热度:291   发布时间:2007-01-03 23:09:57.0
[求助]用户登录代码纠错

我想弄一个网站用户登录的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";
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";
response.sendRedirect(response.encodeURL(redirectURL));
}
else{
rs.close();
stmt.close();
conn.close();
//存在该用户名,但密码不正确,重导回登录页面
String redirectURL="edi";
response.sendRedirect(response.encodeURL(redirectURL));
}
}
else{
rs.close();
stmt.close();
conn.close();
//不存在该用户名,重导回注册页面
String redirectURL="edi";
response.sendRedirect(response.encodeURL(redirectURL));}
}
%>
</body>
</html>

搜索更多相关主题的帖子: 纠错  代码  用户  登录  

----------------解决方案--------------------------------------------------------
有什么问题?
----------------解决方案--------------------------------------------------------
[求助]用户登录代码纠错

无论我输入正确的还是错误的甚至是空的用户名跟密码,网页都没变化。


----------------解决方案--------------------------------------------------------
[求助]用户登录代码纠错
你好,这是我那个登录表单的代码:
<form name="form1" method="post" action="login.jsp">
<div align="right">
<p align="left">用户名:<input name="userName" type="text" value="---请输入您的用户名---">
<br>
<br>
密 码:<input name="Password" type="password">
<br>
<br>
<input type="submit" name="submit" value="登录">
<label>
<input type="submit" name="reset" value="重置">
</label>
</div>
</form>

action="login.jsp"就是我上面一楼的那个代码的文件名
----------------解决方案--------------------------------------------------------
String username=request.getParameter("useName");

:<input name="userName" type="text" value="---请输入您的用户名---">

----------------解决方案--------------------------------------------------------
以下是引用Abby在2007-1-3 23:09:57的发言:

我想弄一个网站用户登录的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";
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";
response.sendRedirect(response.encodeURL(redirectURL));
}
else{
rs.close();
stmt.close();
conn.close();
//存在该用户名,但密码不正确,重导回登录页面
String redirectURL="edi";
response.sendRedirect(response.encodeURL(redirectURL));
}
}
else{
rs.close();
stmt.close();
conn.close();
//不存在该用户名,重导回注册页面
String redirectURL="edi";
response.sendRedirect(response.encodeURL(redirectURL));}
}
%>
</body>
</html>

正如冰封所说!你的usename,username总是写错!


----------------解决方案--------------------------------------------------------

谢谢你们的回复,我知道错了.可是,//输入为空,重导回这个页面
if(username.equal("")||password.length()==0){
String redirectURL="edi";
response.sendRedirect(response.encodeURL(redirectURL));}
当用户名和密码均为空时,页面还是停留在logic.jsp这里,没有回到设定的redirectURL="edi";


----------------解决方案--------------------------------------------------------
以下是引用Abby在2007-1-4 17:17:06的发言:

谢谢你们的回复,我知道错了.可是,//输入为空,重导回这个页面
if(username.equal("")||password.length()==0){
String redirectURL="edi";
response.sendRedirect(response.encodeURL(redirectURL));}
当用户名和密码均为空时,页面还是停留在logic.jsp这里,没有回到设定的redirectURL="edi";

if(username.equal("")||password.length()==0){
String redirectURL="edi";
response.sendRedirect(response.encodeURL(redirectURL));
return;//加个这个你看看
}


----------------解决方案--------------------------------------------------------
哦,好的!我试试。
----------------解决方案--------------------------------------------------------

angeloc,我刚试了,还是老样子。


----------------解决方案--------------------------------------------------------
  相关解决方案