【发布时间】:2015-04-04 07:10:04
【问题描述】:
请看下面的代码
<c:forEach var="patientBean" items="${requestScope['PatientBean']}">
<tr>
<td><img src="images/img1.jpg" width="30px" height="30px"/></td>
<td><c:out value="${patientBean.FirstName}"/><c:out value="${patientBean.MiddleName}"/><c:out value="${patientBean.LastName}"/></td>
<td><c:out value="${patientBean.dob}"/></td>
<td><c:out value="${patientBean.sex}"/></td>
<td><form name="form1" method="post" action="allergies.jsp">
<label>
<input type="submit" name="view" id="1" value="View">
</label>
<input name="idPatient" type="hidden" value=<c:out value="${patientBean.idPatient}"/>>
</c:forEach>
我有一个名为 PatientBean 的 bean。在一个 servlet 中,许多PatientBeans 被填充并添加到ArrayList。上面的代码显示了我如何尝试在 JSP 中访问 ArrayList 并获取其中的 bean 数据。
下面是Servlet,它将请求转发给JSP
request.setAttribute("patientBean", patientBeanList);
RequestDispatcher requestDispatcher = request.getRequestDispatcher("patients.jsp");
requestDispatcher.forward(request, response);
然而它真的没有用。未显示任何数据。我做错了什么?
下面是PatientBean
/**
*
* @author Yohan
*/
public class PatientBean implements Serializable {
private int idPatient;
private String firstName;
private String middleName;
private String lastName;
private Date dob;
private String sex;
/**
* @return the idPatient
*/
public int getIdPatient() {
return idPatient;
}
/**
* @return the firstName
*/
public String getFirstName() {
return firstName;
}
/**
* @return the middleName
*/
public String getMiddleName() {
return middleName;
}
/**
* @return the lastName
*/
public String getLastName() {
return lastName;
}
/**
* @return the dob
*/
public Date getDob() {
return dob;
}
/**
* @return the sex
*/
public String getSex() {
return sex;
}
/**
* @param idPatient the idPatient to set
*/
public void setIdPatient(int idPatient) {
this.idPatient = idPatient;
}
/**
* @param firstName the firstName to set
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* @param middleName the middleName to set
*/
public void setMiddleName(String middleName) {
this.middleName = middleName;
}
/**
* @param lastName the lastName to set
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* @param dob the dob to set
*/
public void setDob(Date dob) {
this.dob = dob;
}
/**
* @param sex the sex to set
*/
public void setSex(String sex) {
this.sex = sex;
}
}
【问题讨论】:
-
@SotiriosDelimanolis:错误。在 JSP 页面中?没有在那个页面上,这就是我得到的全部..
-
那么你有一个名为
PatientBean的请求属性吗? -
@SotiriosDelimanolis:请检查已编辑的问题,..
-
请注意,属性名称区分大小写。您可能应该调用属性
patientBeans(复数),在这种情况下,您可以使用items="${patientBeans}并拥有var="patientBean"。 -
@SotiriosDelimanolis:太棒了..请提供答案..
标签: java jsp servlets arraylist jstl