【发布时间】:2015-01-12 20:37:57
【问题描述】:
在jsp页面中,只打印最先访问的函数。如果首先访问 function-1,则不会打印 function-2。如果首先访问 Function-2,则不会打印 Function-1。请有任何建议。
控制器:
populateTf(tfCount, request, response);
populateSa(saCount, request, response);
response.sendRedirect("testPage.jsp");
//FUNCTION-1
void populateTf(int tfCount, HttpServletRequest request, HttpServletResponse response){
ArrayList<TF> tfList = new ArrayList<TF>();
String field1 = request.getParamter("xyz");
String field2 = request.getParamter("xyz");
String field3 = request.getParamter("xyz");
tfList.add(new TF(field1, field2, field3));
HttpSession session = request.getSession();
session.setAttribute("tfList", tfList);
}
//FUNCTION-2
void populateSa(int saCount, HttpServletRequest request, HttpServletResponse response){
ArrayList<SA> saList = new ArrayList<SA>();
String field1 = request.getParamter("xyz");
saList.add(new SA(field1));
HttpSession session = request.getSession();
session.setAttribute("saList", saList);
}
业务对象:
public class TF{
private String field1, field2, field3;
public TrueFalse(String field1, String field2, String field3) {
this.field1 = field1;
this.field2 = field2;
this.field3 = field3;
}
/* GETTERS AND SETTERS */
}
public class SA{
private String field1;
public ShortAnswer(String field1) {
this.field1 = field1;
}
/* GETTERS AND SETTERS */
}
这里是 JSP 页面:
<table>
<c:forEach items="${sessionScope.tfList}" var="tf">
<tr>
<td>${tf.field1}</td>
<td>${tf.field2}</td>
<td>${tf.field3}</td>
</tr>
</c:forEach>
</table>
<table>
<c:forEach items="${sessionScope.saList}" var="sa">
<tr>
<td>${sa.field1}</td>
</tr>
</c:forEach>
</table>
【问题讨论】:
标签: java jsp model-view-controller taglib