to: zxhong(红) 麻烦您进来一下,急事请教。。

cgddn 2002-11-18 03:12:17
以下是我对用户logon页面的验证代码,写在logonProcess.jsp中,但是有问题发生,就是,如果我随便输入一个用户名和密码,页面不会转到loginAddress.jsp重新输入,而是停留在logonProcess.jsp上,页面一片空白,也不打印出("errors with name or password!");不知道这是为什么?
<%
String username=request.getParameter("userName");
String userpsw=request.getParameter("userPsw");
String query="select name,password,isAdmin,id from address where name='"+username+"'";
loginBean.openConnection();
loginBean.executeQuery(query);
%>

<%while(loginBean.next()){%>

<%if((loginBean.getStr(username).equals(loginBean.getData("name")))&&(userpsw.equals(loginBean.getData("password")))&&username!=null&&userpsw!=null){%>
<%response.sendRedirect("addressList.jsp?isadmin="+loginBean.getData("isAdmin")+"&id="+loginBean.getData("id"));%>

<%}else{%>
<%
out.println("errors with name or password!");
out.println("<a href='loginAddress.jsp'>return and retry!:)</a>");
%>
<%}%>
<%}%>
...全文
20 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zxhong 2002-11-18
  • 打赏
  • 举报
回复

<%if((loginBean.getStr(username).equals(loginBean.getData("name")))&&(userpsw.equals(loginBean.getData("password")))&&username!=null&&userpsw!=null){%>
是不是多了个括好啊!
改为:
<%if(loginBean.getStr(username).equals(loginBean.getData("name")))&& userpsw.equals(loginBean.getData("password"))&&username!=null&&userpsw!=null){%>
cgddn 2002-11-18
  • 打赏
  • 举报
回复
为什么要用那个呢?我改了,可是还是一样的啊。。。:(
它跟getData(String n) 有区别吗?
zxhong 2002-11-18
  • 打赏
  • 举报
回复
建议你用
public String getData(int index) throws SQLException{
return rs.getString(index).trim();
}
这个方法

loginBean.getData(1)

81,094

社区成员

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

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