码迷,mamicode.com
首页 > 编程语言 > 详细

关于 java 上传,下载和导入报java.lang.IllegalStateException异常解决办法

时间:2015-08-14 11:29:26      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

java.lang.IllegalStateException异常解决办法 

最近在使用response.sendRedirect()时出现如下错误:
java.lang.IllegalStateException
            org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:423)

经过分析、查看jdk文档终于找到解决的办法,在response.sendRedirect()方法后加return语句即可,如下:
response.sendRedirect("login.jsp");
            return;

原因是:在程序中两次调用了response.sendRedirect()方法。



jdk5.0文档中很清楚地介绍了出现IllegalStateException异常的可能情况:

1)同一个页面中再次调用response.sendRedirect()方法。
2)提交的URL错误,即不是个有效的URL。 

sendRedirect
            void sendRedirect(java.lang.String location)
            throws java.io.IOException
            Sends a temporary redirect response to the client using the  specified redirect location URL. This method can accept relative URLs;  the servlet container must convert the relative URL to an absolute URL  before sending the response to the client. If the location is relative  without a leading '/' the container interprets it as  relative to the current request URI. If the location is relative with a  leading '/' the container interprets it as relative to the servlet container root. 
            If the response has already been committed, this method  throws an IllegalStateException. After using this method, the response  should be considered to be committed and should not be written to. 

            Parameters: 
            location - the redirect location URL 
            Throws: 
            java.io.IOException - If an input or output exception occurs 
            java.lang.IllegalStateException - If the response was  committed or if a partial URL is given and cannot be converted into a  valid URL

关于 java 上传,下载和导入报java.lang.IllegalStateException异常解决办法

标签:

原文地址:http://www.cnblogs.com/Eric-5279/p/4729099.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!