struts+hibernate登录问题

来源:百度知道 编辑:UC知道 时间:2024/05/08 04:14:13
我随意做了个登录界面。可是错误的用户跟密码都能进去。请大家为我看看我这代码该怎么改:
package com.action;

import java.util.Iterator;
import java.util.List;

import org.hibernate.HibernateException;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class UserLoginAction extends ActionSupport
{
private Integer userid;
private String username;
private String userpassword;
public Integer getUserid() {
return userid;
}
public void setUserid(Integer userid) {
this.userid = userid;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getUserpassword() {
return userpassword;
}
public void setUserpassword(String userpassword) {
this.userpassword = userpassword;
}
public String execute() throws Exception

if(users!=null)
{
Iterator i1=users.iterator();
while(i1.hasNext())
{
User u=(User)i1.next();
if(u.getUserpassword().trim().equals(userpassword))
{
ActionContext.getContext().getSession().put("user" , getUsername());
} else{
//密码不对,你想干啥??
}
}
}

应该是if(users!=null) 那里不对吧?List users = dao1.findByUsername(username); 这个执行完了肯定不为null啊,应该这么写:
if(users==null||users.size()==0){
return error;
}

你分别打印出来username和password看看都是什么值