日期:2014-05-17  浏览次数:20746 次

jsp 页面问题请帮帮忙!
报错问题:
java.lang.NumberFormatException: For input string: " 1"

我做页面跳转的时候接受参数就报了上边的错误,请明白的人帮忙解答一下,谢谢啦.
源代码:

<%
int id = Integer.parseInt(request.getParameter("id"));
int rootId = Integer.parseInt(request.getParameter("rootid"));
%>
<html>
  <head>
  

  </head>
  
  <body>
  <form action="ReplyOk.jsp" method="post">
  <input type="hidden" name="id" value="<%=id%>">
  <input type="hidden" name="rootid" value="<%=rootId %>">
 
  <table border="1">
  <tr>
  <td>
  <input type="text" name="title" size="80">
  </td>
  </tr>
 
  <tr>
  <td>
  <textarea cols="80" rows="12" name="cont"></textarea>
  </td>
  </tr>
  <tr>
  <td>
  <input type="submit" value="提交">
  </td>
  </tr>
 
  </table>
  </form>
  </body>
</html>


------解决方案--------------------
request.getParameter("rootid")改为request.getParameter("rootid").trim()
request.getParameter("id")改为request.getParameter("id").trim()