在User内编写PRivate数据 username、passWord
并且设置set get hashcode equals 方法
代码如下:
package com.zking.bean;public class User { private String username; private String password; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((password == null) ? 0 : password.hashCode()); result = prime * result + ((username == null) ? 0 : username.hashCode()); return result; } @Override //equals判断username and password 是否相同 相同的话就不能登录 public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; User other = (User) obj; if (password == null) { if (other.password != null) return false; } else if (!password.equals(other.password)) return false; if (username == null) { if (other.username != null) return false; } else if (!username.equals(other.username)) return false; return true; }}新手学习中,如有错误,烦请斧正!
http://localhost:8899/testweb 可以跳到登录界面 http://localhost:8899/testweb/login.action 可以跳入点击后的界面,不过登录失败http://localhost:8899/testweb/login.action?username=123&password=xiekun 可以登陆成功新闻热点
疑难解答