//我已经从MySQL中检索了一个结果,并创建了一个数组列表用户。//我已经发送了这个用户数组列表,并通过请求响应对象发送了它。现在我需要显示一个JSP页面。//1.Without //2.With JSTL
//表的名称是user_reg,它有四个字段ID、用户名、密码和电子邮件。//请用示例进行解释。我需要在JSP页面中显示所有字段。但我不想//在JSP上执行jdbc工作
package kinder.dto;
public class User {
private String id;
private String userName;
private String saltedkey;
private String emailId;
private String legalName;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getLegalName() {
return legalName;
}
public void setLegalName(String legalName) {
this.legalName = legalName;
}
public String getEmailId() {
return email;
}enter code here`
public void setEmailId(String emailId) {
this.emailId = emailId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return saltedkey;
}
public void setPassword(String password) {
this.saltedkey = password;
}
}
//dto
package kinder.dto;
public class User {
private String id;
private String userName;
private String saltedkey;
private String emailId;
private String legalName;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getLegalName() {
return legalName;
}
public void setLegalName(String legalName) {
this.legalName = legalName;
}
public String getEmailId() {
return emailId;
}
public void setEmailId(String emailId) {
this.emailId = emailId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return saltedkey;
}
public void setPassword(String password) {
this.saltedkey = password;
}
}
//服务小程序
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
List<User> users = UserDAO.list();
request.setAttribute("users", users); // Will be available as ${products} in JSP
request.getRequestDispatcher("loginSuccess.jsp").forward(request, response);
} catch (SQLException | ClassNotFoundException e) {
throw new ServletException("Cannot obtain products from DB", e);
}
}
//如何在JSP页面中取得这个
3条答案
按热度按时间khbbv19g1#
使用pojo类访问它:
用户名();用户名和密码
u0sqgete2#
使用JSTL
需要创建POJO类
小服务程序
需要更改列表填充逻辑
JSP页面
0kjbasz63#