java.lang.IllegalStateException异常解决办法

阅读: 评论:0

java.lang.IllegalStateException异常解决办法

java.lang.IllegalStateException异常解决办法

 

最近在使用response.sendRedirect()时出现如下错误:
  java.lang.IllegalStateException
  org.tor.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 interdivts it as relative to the current request URI. If the location is relative with a leading '/' the container interdivts 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

本文发布于:2024-01-27 11:59:48,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/17063279871282.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23