无法从下拉菜单中访问所选值

时间:2013-02-15 09:34:27

标签: java drop-down-menu jspx

我的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>    

1 个答案:

答案 0 :(得分:1)

请尝试:

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

并判断这是否解决了您的问题?

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

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

...谢谢

Mr.777