帮帮我看看一个小问题,

来源:互联网 发布:淘宝网一岁宝宝衣服 编辑:程序博客网 时间:2024/04/25 21:25

用户登陆的问题

我用循环就出错,

<%
  String name = new String(request.getParameter("name").getBytes("iso-8859-1"));
  String password = new String(request.getParameter("password").getBytes("iso-8859-1"));
  String  condition="select name,password from user where name='" +name +"' and password='" + password +"'";
  rs=stmt.executeQuery(condition); 

/* rs.last();
int rscount=rs.getRow();
rs.first();

int i=0;
while(i<rscount && !rs.isAfterLast())  */
   //   if (!rs.eof())
if(!rs.next());  //因为表里就一条记录,所有可以不用循环,若有多条记录,必须建立循环!
  {
  if(rs.getString("name").equals(name)&&rs.getString("password").equals(password))
     {
     session.setAttribute("name","name");    
  response.sendRedirect("index.jsp");
     }
  else
     {
  out.print("用户名或密码错误!");%> <a href="dl.jsp">返回</a><%
     }
     }
  stmt.close();
     conn.close();
%>

 

原创粉丝点击