2013-02-15 35 views
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>  

回答

1

请您尝试一下这样的:

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

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

另外,看看你的例外,它看起来像该参数包含一个空字符串。无论你是不是调用合适的参数,或者检查大小写...

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

谢谢...

Mr.777

+0

没关系,'requestInformation.getRequestParameter(“idRoom”)'已经返回'String'。而且我知道'String'是空的,我的问题是为什么它是空的,我该如何解决这个问题。 – 2013-02-15 15:21:17

+0

我告诉过你,你需要调试它....看看参数名称是否正确,参数值是在窗体中,并且正确发送。 – dosdebug 2013-02-15 15:28:20

+0

在Firebug中,我看到: 2013-02-15 15:55:48