我想通过使用servlet
将会话bean内的对象显示在jsp中这是我的servlet
<form action="profile" method="POST">
<input id="User Name" type="text" value="${user.username } " name="userName" /><br>
<input id="Password" type="text" placeholder="Password" name="password" value="${user.password}" size="20" /><br>
<input id="Name" type="text" placeholder="Name" name="Name" value="${user.userInfo}" /><br>
</form>
</div>
</body>
userInfo是一个包含名称的对象.....所以我将如何在userInfo中显示对象....... $ {user.userInfo}的结果只返回数据库引用哪个是Database.UserInformation [id = 401]我将如何访问id内的项目? 这是我的用户信息
@Entity 公共类UserInformation实现Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof UserInformation)) {
return false;
}
UserInformation other = (UserInformation) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "Database.UserInformation[ id=" + id + " ]";
}
}
这是我的用户类
public class Users实现Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String username;
private String password;
@OneToOne
private UserInformation userInfo;
public UserInformation getUserInfo() {
return userInfo;
}
public void setUserInfo(UserInformation userInfo) {
this.userInfo = userInfo;
}
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;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Users)) {
return false;
}
Users other = (Users) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "Database.Users[ id=" + id + " ]";
}
}
答案 0 :(得分:0)
${user.userInfo.name}
这将为您提供userInfo的值,如果它为您提供空值,则检查您的数据库是否为空。很高兴它奏效了。