關於 java 上傳,下載和匯入報java.lang.IllegalStateException異常解決辦法

來源:互聯網
上載者:User

標籤:

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異常解決辦法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.