使用URL将值从JSP传递到SERVLET

时间:2022-03-24 11:52:54

My goal is to pass value from jsp to servlet. I managed to pass the values of reservationId and tableId but NOT staffId.

我的目标是将值从jsp传递给servlet。我设法传递了res​​ervationId和tableId的值,但没有传递staffId。

The error was:

错误是:

java.lang.NumberFormatException: For input string: "staffId"

java.lang.NumberFormatException:对于输入字符串:“staffId”

Why is that so? Is it because staffId is retrieve from DROPDOWN LIST?

为什么会这样?是因为staffId是从DROPDOWN LIST中检索的吗?

Help will be appreciated!

帮助将不胜感激!

<c:forEach items="${table}" var="table">
<tr>
<td>${table.reservationId}</td>
td><select name="staffId">
<c:forEach var="staff" items="${staff}">
<option value="${staff.staffId}">${staff.staffName}</option>
</c:forEach>
</select>
</td>

<td>
<a href="TableEditServlet?action=assign&reservationId=<c:out value="${table.reservationId}"/>&tableId=<%= request.getParameter("tableId") %>&staffId=<c:out value="${staff.staffId}"/>">

<input value="Assign" class="btn"></a></td> </tr>

</c:forEach>

1 个解决方案

#1


0  

You should use JavaScript or JQuery to get data from <select name="staffId" id="someId"> for the selected row.

您应该使用JavaScript或JQuery从所选行的

UPDATE (using javascript)

更新(使用javascript)

... add this javascript section before <body>
<script>
function assign(reservationId) {
document.location="TableEditServlet?action=assign&reservationId="+reservationId+"&staffId="+document.getElementById("staffId_"+reservationId).value;
// add tableId if you need as well
}
</script>
...
    <c:forEach items="${table}" var="table">
    <tr>
    <td>${table.reservationId}</td>
    <td>
    <select name="staffId" id="staffId_${table.reservationId}">
    <c:forEach var="staff" items="${staff}">
    <option value="${staff.staffId}">${staff.staffName}</option>
    </c:forEach>
    </select>
    </td>
    <td>
    <input value="Assign" class="btn" onclick="assign('<c:out value="${table.reservationId}"/>')">
    </td>
    </tr>
    </c:forEach>

#1


0  

You should use JavaScript or JQuery to get data from <select name="staffId" id="someId"> for the selected row.

您应该使用JavaScript或JQuery从所选行的

UPDATE (using javascript)

更新(使用javascript)

... add this javascript section before <body>
<script>
function assign(reservationId) {
document.location="TableEditServlet?action=assign&reservationId="+reservationId+"&staffId="+document.getElementById("staffId_"+reservationId).value;
// add tableId if you need as well
}
</script>
...
    <c:forEach items="${table}" var="table">
    <tr>
    <td>${table.reservationId}</td>
    <td>
    <select name="staffId" id="staffId_${table.reservationId}">
    <c:forEach var="staff" items="${staff}">
    <option value="${staff.staffId}">${staff.staffName}</option>
    </c:forEach>
    </select>
    </td>
    <td>
    <input value="Assign" class="btn" onclick="assign('<c:out value="${table.reservationId}"/>')">
    </td>
    </tr>
    </c:forEach>