【发布时间】:2015-12-31 14:56:50
【问题描述】:
我在将值从 jsp 传递到 java servlet 时遇到问题。 我的学生类有以下字段:id、firstName、lastName、precenseStatus。 字段 precenseStatus 为空,想要在 jsp 中设置“Obecny”、“Nieobecny”或“Spóźniony”字符串值。 我传递给学生对象(学生)的jsp列表。
jsp:
<form action="updatePrecensesServlet" method="post">
<table class="table table-striped">
<thead>
<tr>
<th>Imię</th>
<th>Nazwisko</th>
<th>Obecność</th>
</tr>
</thead>
<tbody>
<c:forEach var="student" items="${students}">
<tr>
<td><c:out value="${student.firstName}" /></td>
<td><c:out value="${student.lastName}" /></td>
<td>
<form role="form">
<c:if test="${student.precenseStatus == 'Obecny'}">
<label class="radio-inline">
<input checked type="radio" name="${student.precenseStatus}" value="Obecny"/>Obecny
</label>
<label class="radio-inline">
<input type="radio" name="${student.precenseStatus}" value="Nieobecny"/>Nieobecny
</label>
<label class="radio-inline">
<input type="radio" name="${student.precenseStatus}" value="Spóźniony"/>Spóźniony
</label>
</c:if>
<c:if test="${student.precenseStatus == 'Nieobecny'}">
<label class="radio-inline">
<input type="radio" name="${student.precenseStatus}" value="Obecny"/>Obecny
</label>
<label class="radio-inline">
<input checked type="radio" name="${student.precenseStatus}" value="Nieobecny"/>Nieobecny
</label>
<label class="radio-inline">
<input type="radio" name="${student.precenseStatus}" value="Spóźniony"/>Spóźniony
</label>
</c:if>
<c:if test="${student.precenseStatus == 'Spó?niony'}">
<label class="radio-inline">
<input type="radio" name="${student.precenseStatus}" value="Obecny"/>Obecny
</label>
<label class="radio-inline">
<input type="radio" name="${student.precenseStatus}" value="Nieobecny"/>Nieobecny
</label>
<label class="radio-inline">
<input checked type="radio" name="${student.precenseStatus}" value="Spóźniony"/>Spóźniony
</label>
</c:if>
<c:if test="${student.precenseStatus != 'Obecny' &&
student.precenseStatus != 'Nieobecny' &&
student.precenseStatus != 'Spó?niony'}">
<label class="radio-inline">
<input type="radio" name="${student.precenseStatus}" value="Obecny"/>Obecny
</label>
<label class="radio-inline">
<input type="radio" name="${student.precenseStatus}" value="Nieobecny"/>Nieobecny
</label>
<label class="radio-inline">
<input type="radio" name="${student.precenseStatus}" value="Spóźniony"/>Spóźniony
</label>
</c:if>
</form>
</td>
</tr>
</c:forEach>
</tbody>
</table>
<button name="students" value="${student}" scope="request" type="submit" class="btn btn-success">Zatwierdź</button>
</form>
updatePrecensesServlet doPost():
System.out.println(request.getParameterValues("students").toString());
或
System.out.println(request.getParameter("students").toString());
不起作用:/
Student{ID=2, firstName=YYY, lastName=XXX, precenseStatus=null}
【问题讨论】:
-
那些单选按钮的名称不是
students。这些单选按钮的名称为${student.precenseStatus}。为什么?你到底在期待什么?