public class ErrTest {
4. public static void main(String[] args) {
5. String numString = "1 ";6. System.out.println(Integer.parseInt(numString));7. }
8. }
错误提示信息如下
Exception in thread "main" java.lang.NumberFormatException: For input string: "1 "
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:458)
at java.lang.Integer.parseInt(Integer.java:499)
at com.geelou.test.ErrTest.main(ErrTest.java:6)
java.lang.IllegalStateException:
getOutputStream() has already been called for this response
解决方法
getOutputStream() has already been called for this response异常出现的原因和解决方法:
具体的原因:jsp编译成servlet之后在函数
_jspService(HttpServletRequest request, HttpServletResponse response)的最后有一段这样的代码:
finally {
if (_jspxFactory != null)
_jspxFactory.releasePageContext(_jspx_page_context);
}
这里是在释放在jsp中使用的对象,会调用response.getWriter(),因为这个方法是和response.getOutputStream()相冲突的!所以会出现以上这个异常。然后当然是要提出解决的办法,其实挺简单的,在使用完输出流以后调用以下两行代码即可:
out.clear();
out = pageContext.pushBody();