试了1/0这种情况,可以正确显示
项目里碰到java.lang.IllegalStateException就直接在页面上抛了一堆异常信息,没有正确转到errorpage
      <error-page>
        <exception-type>java.lang.Exception</exception-type>
        <location>/errorPage.jsp</location>
    </error-page>
谁碰到过或者知道这个?

解决方案 »

  1.   

    我对此的理解是这样的:error-page实际上是一种业务手段,让异常被转到特定页面。
    既然是业务手段,则要求该异常需要从业务代码中抛出(也就是我们自己开发的代码),
    容器只是帮我们转到目标页面而已。而java.lang.IllegalStateException,我们看看这个类的说明:
    Signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation. 这个异常是由jvm或者是由容器抛出的异常(容器判断我们的应用处在不合适的状态,比如:session已经失效,或者已经向客户端返回数据却要求forward等),
    所以当容器认为自身的某些规则都被违背的时候,不应该转向处理业务异常的页面,而是要转向容器自己的出错页面。
      

  2.   

    Signals that a method has been invoked at an illegal or inappropriate time. 
    In other words, the Java environment or Java application is not in an appropriate 
    state for the requested operation.信号的一种方法援引了一个非法或不适当的时间。换句话说, Java环境或Java应用程序是不
    是在一个适当的状态所请求的操作。
      

  3.   

    不是很明白
    不过java.lang.Exception 和java.lang.IllegalStateException不是一类吧
    没有捕捉java.lang.IllegalStateException的处理,不会跳到errorPage.jsp吧
      

  4.   

    IllegalStateException可能不是你应用引起的,而是容器自身的状态异常引起的
      

  5.   

    从来没遇到过!
    原来JAVA我还有那么多要学的!
      

  6.   

    本帖最后由 kokobox 于 2009-05-29 11:54:16 编辑
      

  7.   

    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 &apos;/&apos; the container interprets it as relative to the current request URI. If the location is relative with a leading &apos;/&apos; 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
      

  8.   

    java.lang.IllegalStateException这个异常我碰到过,这个是在页面进行转发或重定向的时候发生的
    异常,也就是说不是在处理你页面内容时引发的异常,所以不会重定向到你指定的错误页面。
    这个异常的原因有可能是你在处理多种情况下的转发或者重定向时,调用了转发或者重定向方法后
    有对request或者response进行了操作的缘故。
    建议楼主检查下转发部分代码,在重定向语句后加一句return。
      

  9.   

    一般的web程序都是需要错误页面的
      

  10.   

    从来没遇到过! 
    原来JAVA我还有那么多要学的!
      

  11.   

    不过java.lang.Exception 和java.lang.IllegalStateException不是一类吧 
    没有捕捉java.lang.IllegalStateException的处理,不会跳到errorPage.jsp吧
      

  12.   

    你可以试试   捕获  java.lang.Throwable   不知道能不能解决问题
      

  13.   

    <error-page>
            <exception-type>java.lang.Exception</exception-type>
            <location>/errorPage.jsp</location>
        </error-page>
    是由容器业处理异常,然后跳到指定的错误页面,切记,不要在业务代码中用try {}catch{}代码手动捕捉异常,
    而是用throw抛出异常让容器来处理,否则就不能达到预定的效果。
      

  14.   


    我不这么认为!!IndexOutOfBoundsException 也是运行时异常,jsp页面也可以显示。JVM异常通过包装是可以通过友好方式显示的。
      

  15.   

        <xsd:sequence>
          <xsd:choice>
    <xsd:element name="error-code"
         type="javaee:error-codeType"/> <xsd:element name="exception-type"
         type="javaee:fully-qualified-classType">
      <xsd:annotation>
        <xsd:documentation>       The exception-type contains a fully qualified class
          name of a Java exception type.     </xsd:documentation>
      </xsd:annotation>
    </xsd:element>
          </xsd:choice>      <xsd:element name="location"
       type="javaee:war-pathType">
    <xsd:annotation>
      <xsd:documentation>     The location element contains the location of the
        resource in the web application relative to the root of
        the web application. The value of the location must have
        a leading `/'.   </xsd:documentation>
    </xsd:annotation>
          </xsd:element>
        </xsd:sequence>如果按照上述方式配置,那你的代码逻辑可能不是以此及彼这种方式写的。慢慢研究吧!采用工具观察方法栈,是否向上一层越进!
      

  16.   

    查了一下,据说output stream 已经被 flushed 之后,tomcat的error-page就无法拦截到这个错误了也许是error-page的一个问题了
      

  17.   

    我同意一楼的说法,既然是业务的话我觉得就在业务里做程序的判断比如用try{}cach{在着转到异常的页面不就好了吗?}
      

  18.   

    楼主在web.xml里面的配置,只能针对视图层jsp页面的Exception,
    也就是说只能在jsp 页面内部发生 Exception 时,才会做相应的跳转,
    如果是在数据访问层,业务层,或是在action层....里面发生Exception ,上面的配置就没有用。
    最好的做法是把所有的Exception 抛到 mvc 的控制层里,然后在类似struts mvc 、 spring mvc 的配置文件中,配置一个异常页面,就能达到目的了。