Jsp登录语句!帮忙看看

sensory 2003-05-15 09:09:20
<%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<jsp:useBean id="user" scope="page" class="user.db" />
<%
Connection con = user.getConn() ;
Statement stmt = con.createStatement() ;
String userid = request.getParameter("nameId") ;
userid = user.ex_chinese(userid) ;
String pwd = request.getParameter("pwd") ;
pwd = user.ex_chinese(pwd) ;
String sql = "select from visiter where 用户名='"+userid+"' and 密码='"+pwd+"'" ;
ResultSet rs = stmt.executeQueary(sql) ; //有问题???
if (rs.next())
{
....
}
try {
stmt.close();
con.close();
String msg = "登录成功!" ;
}
catch (Exception ex) {

}
%>
<body>
<%=msg%>
</body>
</html>


我的添加是成功的.现在是个登录的判断,就是数据库有纪录就登录 没有就不登录.
方法有 我不会写JSP的语句
大家看看怎样写??
3x
...全文
12 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
sensory 2003-05-15
  • 打赏
  • 举报
回复
改成while同样的问题!!!
郁闷!

<%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<jsp:useBean id="user" scope="page" class="user.db" />
<%
Connection con = user.getConn() ;
Statement stmt = con.createStatement() ;
String userid = request.getParameter("nameId") ;
userid = user.ex_chinese(userid) ;
String pwd = request.getParameter("pwd") ;
pwd = user.ex_chinese(pwd) ;
String msg = null ;
String sql = "select * from visiter where 用户名='"+userid+"' and 密码='"+pwd+"'" ;
ResultSet rs = stmt.executeQuery(sql) ;
if (!rs.next())
{
msg="登录不成功";
}
else
{
msg="登录成功";
}

try {
stmt.close();
con.close();

}
catch (Exception ex) {

}
%>
<body>
<%=msg%>
</body>
</html>


怎么回事???
黑马 2003-05-15
  • 打赏
  • 举报
回复
if (rs.next())

改成While(rs.next()),如果有记录的话,就说明可以登陆,否则不能登陆
sensory 2003-05-15
  • 打赏
  • 举报
回复
<%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<jsp:useBean id="user" scope="page" class="user.db" />
<%
Connection con = user.getConn() ;
Statement stmt = con.createStatement() ;
String userid = request.getParameter("nameId") ;
userid = user.ex_chinese(userid) ;
String pwd = request.getParameter("pwd") ;
pwd = user.ex_chinese(pwd) ;
String msg = "登录成功!" ;
String sql = "select * from visiter where 用户名='"+userid+"' and 密码='"+pwd+"'" ;
ResultSet rs = stmt.executeQuery(sql) ;
if (rs.next())
//int intRowCount = rs.getInt(1);
// if (intRowCount!=0)
{
//response.write("登录成功");
msg=msg+"ffdd";
//System.out.println("Connection created!");
}
else
{
//response.write("登录不成功");
msg=msg+"love";
//System.out.println("Connection created!");
}

try {
stmt.close();
con.close();

}
catch (Exception ex) {

}
%>
<body>
<%=msg%>
</body>
</html>

为什么密码对不对都事"登录成功love!"?????
newmember 2003-05-15
  • 打赏
  • 举报
回复
毛病好象都被前两者挑出来了

不过你的try语句最好还是改进一下
wanggangytsoft 2003-05-15
  • 打赏
  • 举报
回复
up
leshui 2003-05-15
  • 打赏
  • 举报
回复
up
moumouren 2003-05-15
  • 打赏
  • 举报
回复
sql = "select * from visiter where 用户名='"+userid+"' and 密码='"+pwd+"'" ;
kenshin_z 2003-05-15
  • 打赏
  • 举报
回复
拼错了stmt.executeQueary(sql) ,应该是stmt.executeQuery(sql)吧!

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧