| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付买域名,送MP3、MP4
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY买空间,免费送域名(厦门中资源)
共有 947 人关注过本帖
标题:[求助]用户登录代码纠错
收藏  订阅  推荐  打印 
Abby
Rank: 1
等级:新手上路
帖子:28
积分:380
注册:2007-1-3
[求助]用户登录代码纠错

我想弄一个网站用户登录的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>

搜索更多相关主题的帖子: 纠错  代码  用户  登录  
2007-1-3 23:09
千里冰封
Rank: 12Rank: 12Rank: 12
来自:灌水之王
等级:版主
威望:155
帖子:28360
积分:4616
注册:2006-2-26

有什么问题?

可惜不是你,陪我到最后
2007-1-3 23:15
Abby
Rank: 1
等级:新手上路
帖子:28
积分:380
注册:2007-1-3
[求助]用户登录代码纠错

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

2007-1-3 23:40
Abby
Rank: 1
等级:新手上路
帖子:28
积分:380
注册:2007-1-3
[求助]用户登录代码纠错

你好,这是我那个登录表单的代码:
<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"就是我上面一楼的那个代码的文件名
2007-1-3 23:48
千里冰封
Rank: 12Rank: 12Rank: 12
来自:灌水之王
等级:版主
威望:155
帖子:28360
积分:4616
注册:2006-2-26

String username=request.getParameter("useName");

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

可惜不是你,陪我到最后
2007-1-4 09:16
angeloc
Rank: 12Rank: 12Rank: 12
等级:贵宾
威望:36
帖子:1353
积分:13680
注册:2006-11-21

以下是引用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.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>

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


老牛明知夕阳晚,不用扬鞭自奋蹄; Angelo\'s BLOG
2007-1-4 16:28
Abby
Rank: 1
等级:新手上路
帖子:28
积分:380
注册:2007-1-3

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

2007-1-4 17:17
angeloc
Rank: 12Rank: 12Rank: 12
等级:贵宾
威望:36
帖子:1353
积分:13680
注册:2006-11-21

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

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

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


老牛明知夕阳晚,不用扬鞭自奋蹄; Angelo\'s BLOG
2007-1-4 17:20
Abby
Rank: 1
等级:新手上路
帖子:28
积分:380
注册:2007-1-3

哦,好的!我试试。
2007-1-4 17:29
Abby
Rank: 1
等级:新手上路
帖子:28
积分:380
注册:2007-1-3

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

2007-1-4 17:32
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.207124 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved