0

我的 jspx 页面上的下拉列表有问题。我看到页面上显示了变量值,但我无法获取所选值。输入字符串为空,所以我得到

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

在这一行:

int idRoom = Integer.parseInt(requestInformation.getRequestParameter("idRoom"));

这是我的 jspx 页面:

<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
version="2.0">
<jsp:directive.page contentType="text/html; charset=Utf-8"/>
<html>
    <head>
    <title><fmt:message bundle="${loc}" key="page.newOrders"/></title>
</head>
<body>
<jsp:directive.include file="/jsp/header.jspx"/>
<h2><fmt:message bundle="${loc}" key="label.greeting"/>, ${user.firstName} ${user.lastName}.</h2>
        <table cellspacing="15">
        <tr>                
        <td align="center"><b><fmt:message bundle="${loc}" key="field.idOrder"/>:</b></td>
        <td align="center"><b><fmt:message bundle="${loc}" key="field.availableRooms"/>:</b></td>
        </tr>
        <c:forEach items="${orderList}" var="cell">
        <tr>                                                
            <td align="center">${cell.id}</td>
                <c:choose>
                    <c:when test="${cell.roomList == null}">
                        <td align="center"><fmt:message bundle="${loc}" key="message.noRooms"/></td>
                    <td></td>                               
                </c:when>
                <c:otherwise>
                <form action="Controller" method="get" id="acceptForm">
                    <td align="center">
                            <select name="selectedRoom">
                            <c:forEach items="${cell.roomList}" var="room">
                            <option value="${room.id}">${room.id}</option>
                        </c:forEach>
                    </select>
                    </td>
                    <td align="center">
                        <fmt:message bundle="${loc}" key="button.accept" var="accept"/>
                    <a href="Controller?command=accept&amp;idOrder=${cell.id}&amp;idRoom=${selectedRoom}" onclick="document.getElementById('acceptForm').submit()">${accept}</a>                                  
                    </td>                                                   
                </form>                                                         
                </c:otherwise>
            </c:choose>          
                <td align="center">
                <fmt:message bundle="${loc}" key="message.rejectOrder" var="reject"/>
                    <c:url value="Controller" var="rejectUrl">
                        <c:param name="command" value="reject"/>
                    <c:param name="idOrder" value="${cell.id}"/>
                </c:url>
                    <a href="${rejectUrl}" onClick="return window.confirm('${reject}')">
                        <fmt:message bundle="${loc}" key="button.reject"/>
                    </a>
            </td>                               
            </tr>
            </c:forEach>
    </table>            
    <jsp:directive.include file="/jsp/footer.jspx"/>
    </body>
</html>
</jsp:root>    
4

1 回答 1

1

请尝试如下:

int idRoom = Integer.parseInt(requestInformation.getRequestParameter("idRoom").toString());

并告诉这是否解决了您的问题?

此外,查看您的异常,该参数似乎包含一个空字符串。要么你没有调用正确的参数,要么检查是否区分大小写......

或者使用 Firebug 确保请求包含名称为 idRoom 的参数

谢谢...

777先生

于 2013-02-15T09:51:48.207 回答