關(guān)于 java 上傳,下載和導(dǎo)入報(bào)java.lang.IllegalStateException異常解決辦法
java.lang.IllegalStateException異常解決辦法
最近在使用response.sendRedirect()時(shí)出現(xiàn)如下錯(cuò)誤:
java.lang.IllegalStateException
org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:423)
經(jīng)過分析、查看jdk文檔終于找到解決的辦法,在response.sendRedirect()方法后加return語句即可,如下:
response.sendRedirect("login.jsp");
return;
原因是:在程序中兩次調(diào)用了response.sendRedirect()方法。
jdk5.0文檔中很清楚地介紹了出現(xiàn)IllegalStateException異常的可能情況:
1)同一個(gè)頁面中再次調(diào)用response.sendRedirect()方法。
2)提交的URL錯(cuò)誤,即不是個(gè)有效的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

浙公網(wǎng)安備 33010602011771號