`
huibin
  • 浏览: 750400 次
  • 性别: Icon_minigender_1
  • 来自: 郑州
社区版块
存档分类
最新评论

java.lang.IllegalStateException异常解决办法

    博客分类:
  • JSP
阅读更多

最近在使用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 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


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/leather0906/archive/2010/01/26/5257969.aspx

分享到:
评论

相关推荐

    java.lang.IllegalStateException: Cannot call sendError() after the response has

    在Java的Web开发中,`java.lang.IllegalStateException: Cannot call sendError() after the response has been committed` 是一个常见的错误,通常发生在尝试在HTTP响应已经发送到客户端之后调用`sendError()`方法...

    Android异常 java.lang.IllegalStateException解决方法

    1. java.lang.IllegalStateException: No wrapped connection. 2.java.lang.IllegalStateException: Adapter is detached. 原因: 1.单线程一次执行一个请求可以正常执行,如果使用多线程,同时执行多个请求时就会...

    Java异常之—-Caused by: java.lang.IllegalStateException: Method has too many Body parameters

    异常:Caused by: java.lang.IllegalStateException: Method has too many Body parameters Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract ...

    java.lang.IllegalStateException: OutputStream already obtain

    标题 "java.lang.IllegalStateException: OutputStream already obtain" 涉及到的是Java编程中的一个常见错误,特别是当处理I/O流时。这个异常通常在尝试获取已经存在的OutputStream实例时抛出,表明该输出流已经被...

    Failed to convert value of type ‘java.lang.String’ to required type ‘java.util.Date’; nested except

    Type 异常报告 消息 Failed to convert ... nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.util.Date': no matching editors or co

    The full error is: java.lang.IllegalState

    在Java中,`IllegalStateException`是`java.lang`包下的一个运行时异常。它是由执行了非法操作(例如,线程已经启动后尝试启动,或者在没有正确设置某些必需状态的情况下调用方法)的代码引发的。这个异常通常伴随着...

    spring入门好教程

    Spring框架,由Rod Johnson创立并由Interface21公司推广,自诞生以来,它就致力于简化Java企业级应用(J2EE)的开发,提供了一种非侵入式的解决方案,极大地提高了开发效率。它的目标不仅仅是解决单一层次的问题,...

    action-buffer:提供了在处理后台任务时避免片段过渡期间出现 IllegalStateException 的示例

    这个存储库提供了一种在处理片段传输和后台任务时避免“java.lang.IllegalStateException:Can not perform this action after onSaveInstanceState”的方法。 您可以在的非常权威的阅读有关该问题和可能的解决方案...

    Tomcat启动springboot项目war包报错:启动子级时出错的问题

    这个错误信息出现在`java.lang.IllegalStateException`中,具体是在`ContainerBase.addChildInternal`方法抛出的,这表明在尝试添加或启动Spring Boot的web应用(war包)作为Tomcat的一个子容器时发生了问题。...

    Android异常处理

    在Android开发中,由于其基于Java语言,因此异常处理机制也遵循Java的标准。本文旨在深入探讨Android开发中异常处理的相关概念和技术细节。 ##### 1.1 异常机制的作用 异常机制的主要作用是在程序执行过程中出现...

    tomcat部署多个项目.pdf

    在多个项目中,可能会遇到 `java.lang.IllegalStateException` 异常,例如: `java.lang.IllegalStateException: Web app root system property already set to dif` 这个异常是因为多个项目中的 `web.xml` 文件中...

    借助Ehcache缓存框架实现对页面的缓存Demo

    java.lang.IllegalStateException at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1600) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader....

    java 中 request.getSession(true、false、null)的区别

    如果在响应已提交的情况下尝试创建会话,容器可能会抛出`IllegalStateException`。 1. `HttpServletRequest.getSession(true)`:这个调用等同于`HttpServletRequest.getSession()`。它表示如果当前请求中没有会话,...

    解决struts2下载异常的jar包 struts2-sunspoter-stream-1.0.jar

    在struts2中使用result里type="stream"的结果类型时,可以实现文件的下载管理,使用时也是比较顺畅,但是当在“下载提示窗口”中点击“取消按钮”时,总是报出“java.lang.IllegalStateException”异常,异常内容...

    weblogic12c部署webservice错误问题WSSERVLET11

    错误信息"无法解析运行时描述符: java.lang.IllegalStateException: MASM0001:"指出在部署Web服务时遇到了异常情况。这个错误代码MASM0001通常与WebLogic的模块组装(Module Assembly)过程有关,该过程是将应用组件...

    Java常见异常

    以下是一些Java中常见的异常及其解决办法: 1. **Caused by: line 1:188: expecting CLOSE, found 'null'** 这个错误通常表示解析错误,可能是因为在XML或HQL(Hibernate查询语言)中遗漏了关闭的括号或其他语法...

    java常见异常汇总

    **异常描述**:在使用 HQL (Hibernate Query Language) 时,如果没有给表名添加别名,可能会引发 `java.lang.IllegalStateException`。 **原因分析**:在 HQL 查询语句中,如果没有为表指定别名,HQL 解析器将无法...

    jsp的跳转方式总结

    * 不能在 response.sendRedirect() 之前使用 out.flush(),否则将抛出 java.lang.IllegalStateException 异常。 * 跳转后,浏览器地址栏将发生变化。 * 如果跳转到不同主机下,response.sendRedirect() 之后的语句将...

    Spring 3.0所需jar文件和对应的配置文件

    nested exception is java.lang.IllegalStateException: Context namespace element 'component-scan' and its parser class [org.springframework.context.annotation.ComponentScanBeanDefinitionParser] are ...

Global site tag (gtag.js) - Google Analytics