SSHTest

--------------------------------------------
UserDAO

  public List<String> findByProperty(String usernames) {
			  Session session =HibernateSessionFactory.getSession(); 
		  Transaction trans =ession.beginTransaction(); 
		  Query query = session
			  .createQuery("select u.username from Users u where u.username = ?");
			  query.setString(0,usernames); 
			  List<String> username =query.list();
			  trans.commit();
			  session.close(); 
			  return username;

---------------------------------------------
  public List<String> findByProperty(String usernames) {
			  Session session =HibernateSessionFactory.getSession(); 
		  Transaction trans =ession.beginTransaction(); 
		  Query query = session
			  .createQuery("select u.username from Users u where u.username = ?");
			  query.setString(0,usernames); 
			  List<String> username =query.list();
			  trans.commit();
			  session.close(); 
			  return username;
----------------------------------------------------------



public class LoginActionImpl implements ILoginAction {
	
	private Users users;
	private UserServiceImpl loginService;
	public UserServiceImpl getLoginService() {
		System.out.println("LoginActionImpl getLoginService"+loginService);
		return loginService;
	}

	public void setLoginService(UserServiceImpl loginService) {
		System.out.println("LoginActionImpl setLoginService"+loginService);
		this.loginService = loginService;
	}
	public Users getUsers() {
		
		System.out.println("LoginActionImpl Action getUsers"+users);
		
		return users;
	}

	public void setUsers(Users users) {
		System.out.println("LoginActionImpl Action setUsers"+users);
		this.users = users;
	}

	public String execute() {
		
		UserServiceImpl loginService= new UserServiceImpl(); 
		System.out.println("LoginActionImpl  execute()执行了");
		System.out.println(users.getPassword()+" "+users.getUsername());
		
		Boolean isFound = loginService.validateLogin(users.getUsername(),users.getPassword());
		
		
		System.out.println("LoginACtion isFound"+isFound);
		if(isFound==true){
			return "success";
		}else{
			return "login";
		}
		
		UsersDAOImpl usersDao = new UsersDAOImpl();
		
		List<Long> userID=usersDao.findByID(users.getUsername(),users.getPassword());
		System.out.println(users.getUsername()+" "+users.getPassword());
		if (userID.size()!=0 ){
			return "success";
		} else {
			return "login";
		}		
	}

}

你可能感兴趣的:(test)