java.lang.IllegalStateException

来源:互联网 发布:办公室有老鼠 知乎 编辑:程序博客网 时间:2024/06/04 19:00
我过去遇到这个问题是因为多次调用一个已经关闭的对象。
比如:同一个页面中再次调用response.sendRedirect()方法。还有可能是提交的URL错误,即不是个有效的URL。
我建议你看看是不是把response.sendRedirect()放到循环里了,或者是多次调用了。API上说调用sendRedirect()方法后,response就已经是close的了。
UserBean ub = new UserBean();if(ub.isExist(username)){//当然我们也是可以加上提示信息的response.sendRedirect("register.jsp");}else if(ub.add(username,password1)){flag = true;}if(flag){System.out.println("flag=true");response.sendRedirect("login.jsp");}else{System.out.println("flag=false");response.sendRedirect("register.jsp");}


这段代码当中出现了两次调用response的情况,于是乎出现了上述错误。

首先输入了一个已经注册过的用户名,然后本应该跳转到registe里卖弄,但是后面还有if else所以就又实用了一次response,于是就出错了。