我有一個對象(集合),我正在根據對象的狀態構建一個JSP頁面之前請求。傳遞集合作爲來自JSP的請求對象
Map<Integer, QuestionBO> questionsIdsMap = new TreeMap<Integer, QuestionBO>();
for (QuestionBO question : questionsForSubject) {
questionsIdsMap.put(question.getQuestionId(), question);
}
request.setAttribute("questionsForSubject", questionsIdsMap);
然後我對錶單做一些操作並將整個頁面提交回servlet進行處理。
<jsp:useBean id="questionsForSubject" class="java.util.Map" scope="request"/>
<c:if test="${not empty questionsForSubject}">
<form action="/TutorWebApp/controller" method="POST" name="addQuestionForm">
<input type="hidden" name="command" value="add_question_list" />
<input type="hidden" name="testName" value="${testName}"/>
<input type="hidden" name="questionsForSubject" value="${questionsForSubject}"/>
<table border ="1">
<tbody>
<c:forEach items="${questionsForSubject.keySet()}" var="questionID">
<tr>
<td>
<input type="checkbox" name ="choosen_question" value="${questionID}">
${questionsForSubject.get(questionID).getQuestion()}
<br />
</td>
</tr>
</c:forEach>
</tbody>
</table>
<input type="submit" value="Add questions"/>
</form>
</c:if>
什麼是前面提到的集合傳遞給Servlet端的傳統方式?
我應該沒有任何框架。
我看到了這個帖子。我嘗試將代碼request.getSession()。setAttribute(「questionsForSubject」)代碼放在jsp上,並在servlet上獲取此值作爲代碼request.getSession()。getAttribute(「questionsForSubject」)代碼。但是,在這種情況下值對象等於NULL。 – Ray