才子佳人博客

我的故事我讲述

java.lang.IllegalStateException异常解决办法
 
来源:xjh  编辑:xjh  2007-06-29

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
voidsendRedirect(java.lang.Stringlocation)
throwsjava.io.IOException
SendsatemporaryredirectresponsetotheclientusingthespecifiedredirectlocationURL.ThismethodcanacceptrelativeURLs;theservletcontainermustconverttherelativeURLtoanabsoluteURLbeforesendingtheresponsetotheclient.Ifthelocationisrelativewithoutaleading/thecontainerinterpretsitasrelativetothecurrentrequestURI.Ifthelocationisrelativewithaleading/thecontainerinterpretsitasrelativetotheservletcontainerroot.
Iftheresponsehasalreadybeencommitted,thismethodthrowsanIllegalStateException.Afterusingthismethod,theresponseshouldbeconsideredtobecommittedandshouldnotbewrittento.

Parameters:
location-theredirectlocationURL
Throws:
java.io.IOException-Ifaninputoroutputexceptionoccurs
java.lang.IllegalStateException-IftheresponsewascommittedorifapartialURLisgivenandcannotbeconvertedintoavalidURL


分类:网络日志| 查看评论
相关文章
文章点击排行
本年度文章点击排行
发表评论:
  • 昵称: *
  • 邮箱: *
  • 网址:
  • 评论:(最多100字)
  • 验证码: