# error-page geht nicht



## *java* (12. Nov 2009)

hallo,

ich habe eine web anwednung und möchte, dass sobal eine java.lang.exception auftritt.ich habe versucht das ganze in der web.xml einzubauen wie folgt:


```
<error-page>  
  <exception-type>java.lang.Exception</exception-type>  
  <location>/faces/error.jsf</location>  
 </error-page>  


<error-page>
 <error-code>500</error-code> 
  <location>/faces/error.jsf</location>  
        </error-page>
```

beides funktioniert nicht!wenn ich einfach ein nullpointerexception auslöse wird immer der standardfehler 500 von tomct angezeigt.

was mach ich falsch?

danke und grüße


----------



## HLX (17. Nov 2009)

Vielleicht ein Folgefehler, der beim Anzeigen der Fehlerseite auftritt.

Versuchs mal anstelle der JSF-Seite mit einer einfachen JSP-Seite im Wurzelverzeichnis deiner Webanwendung. Lass diese Seite nur einen simplen Text ausgeben.

Übrigens: Falls unterwegs ein "java.lang.Error" auftritt wird dieser nicht abgefangen. Zum Abfangen müsstest du den "exception-type" auf "java.lang.Throwable" setzen.


----------



## asdfdafsdfs (26. Nov 2009)

hallo,

also es funktioniert immer noch nicht hab es versucht mit einer jsp.

hab extra 

        <error-page>  
  <exception-type>java.lang.Throwable</exception-type>  
  <location>/faces/Page2.jsp</location>  
 </error-page> 

verwendet.

und ne nullpointerexception geworfen. aber die definition reagiert nicht!

bitte nochmal um hilfe.

gruß


----------



## asdfdafsdfs (30. Nov 2009)

hallo,

keiner ne ahnung. ich verstehe es nicht wirklich. bin schon wieder den ganzen mrogen am suchen und probieren. muss ich ihrgend wie die position in der web.xml beachten? ich habe es direkt unter die definition der startpage gesetzt.

vielen dank und grüße


----------



## HLX (30. Nov 2009)

Wie sieht die web.xml komplett aus?


----------



## asdfdafsdfs (30. Nov 2009)

[xml]
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>
    <context-param>
        <param-name>com.sun.faces.validateXml</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>com.sun.faces.verifyObjects</param-name>
        <param-value>false</param-value>
    </context-param>
    <filter>
        <filter-name>UploadFilter</filter-name>
        <filter-class>com.sun.webui.jsf.util.UploadFilter</filter-class>
        <init-param>
            <description>The maximum allowed upload size in bytes.  If this is set to a negative value,
     there is no maximum.  The default value is 1000000.</description>
            <param-name>maxSize</param-name>
            <param-value>1000000</param-value>
        </init-param>
        <init-param>
            <description>The size (in bytes) of an uploaded file which, if it is exceeded, will cause the file 
    to be written directly to disk instead of stored in memory.  Files smaller than or equal to this size     
    will be stored in memory.  The default value is 4096.</description>
            <param-name>sizeThreshold</param-name>
            <param-value>4096</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>UploadFilter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <init-param>
            <param-name>javax.faces.LIFECYCLE_ID</param-name>
            <param-value>com.sun.faces.lifecycle.PARTIAL</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>ExceptionHandlerServlet</servlet-name>
        <servlet-class>com.sun.errorhandler.ExceptionHandler</servlet-class>
        <init-param>
            <param-name>errorHost</param-name>
            <param-value>localhost</param-value>
        </init-param>
        <init-param>
            <param-name>errorPort</param-name>
            <param-value>24444</param-value>
        </init-param>
    </servlet>
    <servlet>
        <servlet-name>ThemeServlet</servlet-name>
        <servlet-class>com.sun.webui.theme.ThemeServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>ExceptionHandlerServlet</servlet-name>
        <url-pattern>/error/ExceptionHandler</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>ThemeServlet</servlet-name>
        <url-pattern>/theme/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/Page1.jsp</welcome-file>
        </welcome-file-list>
    <error-page>
        <exception-type>java.lang.Throwable</exception-type> 
        <location>/faces/test.jsp</location>
    </error-page>
    <jsp-config>
        <jsp-property-group>
            <url-pattern>*.jspf</url-pattern>
            <is-xml>true</is-xml>
        </jsp-property-group>
        </jsp-config>
    </web-app>[/xml]


----------



## HLX (30. Nov 2009)

Das ist dein Problem:
[XML]
<servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
...
<error-page>
    <exception-type>java.lang.Throwable</exception-type> 
    <location>/faces/test.jsp</location>
</error-page>
[/XML]
Durch dieses Servlet-Mapping wird im Fehlerfall nicht die JSP-Seite, sondern das FaceServlet aufgerufen.

Versuch folgendes:
[XML]
<error-page>
    <exception-type>java.lang.Throwable</exception-type> 
    <location>/test.jsp</location>
</error-page>
[/XML]
Die JSP-Seite muss dabei im Wurzelverzeichnis deiner Webanwendung liegen.


----------



## asdfdafsdfs (30. Nov 2009)

hallo,

danke für die antwort.

das scheint aber auch nicht zu gehen.
warum. ich werfe in ne nullpointersxc. damit sollte es ja gehen. aber es erscheint nur ein 500 fehler.

gruß und danke


----------



## HLX (30. Nov 2009)

Möglicherweise wird die Exception von JSF oder dem ServletContainer in HTTP-Fehlercode 500umgewandelt. Versuchs mal mit einer anderen Exception, die nicht von RuntimeException erbt, z.B. java.lang.Exception.


----------



## asdfdafsdfs (1. Dez 2009)

hallo hlx,

das problem ist, dass ich eine normale exception nicht werfen darf. ich verwende netbeans und die page ist von AbstractPageBean abgeleitet. die meldung ist "unreported exception java.io.exception must be caught or declared to be thrown". 

die page hat folgenden java code:


```
import com.sun.rave.web.ui.appbase.AbstractPageBean;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import javax.faces.FacesException;

public class test extends AbstractPageBean{
    // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">

    /**
     * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
     * This method is automatically generated, so any user-specified code inserted
     * here is subject to being replaced.</p>
     */
    private void _init() throws Exception {
    }

    // </editor-fold>
    /**
     * <p>Construct a new Page bean instance.</p>
     */
    public test() {
    }

    /**
     * <p>Callback method that is called whenever a page is navigated to,
     * either directly via a URL, or indirectly via page navigation.
     * Customize this method to acquire resources that will be needed
     * for event handlers and lifecycle methods, whether or not this
     * page is performing post back processing.</p>
     * 
     * <p>Note that, if the current request is a postback, the property
     * values of the components do <strong>not</strong> represent any
     * values submitted with this request.  Instead, they represent the
     * property values that were saved for this view when it was rendered.</p>
     */
    @Override
    public void init() {
        // Perform initializations inherited from our superclass
        super.init();
        // Perform application initialization that must complete
        // *before* managed components are initialized
        // TODO - add your own initialiation code here
        
        // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
        // Initialize automatically managed components
        // *Note* - this logic should NOT be modified
        try {
            _init();
        } catch (Exception e) {
            log("Page1 Initialization Failure", e);
            throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
        }
        
        // </editor-fold>
        // Perform application initialization that must complete
        // *after* managed components are initialized
        // TODO - add your own initialization code here
        
        
    }

    /**
     * <p>Callback method that is called after the component tree has been
     * restored, but before any event processing takes place.  This method
     * will <strong>only</strong> be called on a postback request that
     * is processing a form submit.  Customize this method to allocate
     * resources that will be required in your event handlers.</p>
     */
    @Override
    public void preprocess() {
    }

    /**
     * <p>Callback method that is called just before rendering takes place.
     * This method will <strong>only</strong> be called for the page that
     * will actually be rendered (and not, for example, on a page that
     * handled a postback and then navigated to a different page).  Customize
     * this method to allocate resources that will be required for rendering
     * this page.</p>
     */
    @Override
    public void prerender() {
        throw new java.lang.Exception("");
        //throw new NullPointerException("ddd");
    }

    /**
     * <p>Callback method that is called after rendering is completed for
     * this request, if <code>init()</code> was called (regardless of whether
     * or not this was the page that was actually rendered).  Customize this
     * method to release resources acquired in the <code>init()</code>,
     * <code>preprocess()</code>, or <code>prerender()</code> methods (or
     * acquired during execution of an event handler).</p>
     */
    @Override
    public void destroy() {
    }

}
```

ein thrown ist iin diesem fall ja nicht möglich.


----------



## HLX (1. Dez 2009)

Wenn nun 500 zurückkommt scheint sich ja zumindest schonmal was zu tun. Werf mal einen Blick in die Log-Dateien des Tomcat. Möglicherweise wird dort eine Exception oder ein anderweitiges Fehlverhalten angezeigt. Es könnte sein, dass durch einen Folgefehler der Error-Code 500 erzeugt wird.


----------



## asdfdafsdfs (2. Dez 2009)

hi,

also das log gibt folgende her:


```
02.12.2009 11:22:53 com.sun.faces.lifecycle.LifecycleImpl phase
WARNUNG: executePhase(RENDER_RESPONSE 6,com.sun.faces.context.FacesContextImpl@19d96b1) threw exception
com.sun.rave.web.ui.appbase.ApplicationException: ddd
        at com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.cleanup(ViewHandlerImpl.java:594)
        at com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.renderView(ViewHandlerImpl.java:311)
        at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
        at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
        at com.sun.faces.extensions.avatar.lifecycle.PartialTraversalLifecycle.render(PartialTraversalLifecycle.java:106)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.sun.webui.jsf.util.UploadFilter.doFilter(UploadFilter.java:267)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException: ddd
        at webapplication1.Page1.prerender(Page1.java:99)
        at com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.prerender(ViewHandlerImpl.java:806)
        at com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.renderView(ViewHandlerImpl.java:303)
        ... 23 more
02.12.2009 11:22:53 com.sun.faces.lifecycle.LifecycleImpl phase
WARNUNG: phase(RENDER_RESPONSE 6,com.sun.faces.context.FacesContextImpl@19d96b1) threw exception: com.sun.rave.web.ui.appbase.ApplicationException: ddd ddd
com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.cleanup(ViewHandlerImpl.java:594)
com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.afterPhase(ViewHandlerImpl.java:470)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:280)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
com.sun.faces.extensions.avatar.lifecycle.PartialTraversalLifecycle.render(PartialTraversalLifecycle.java:106)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
com.sun.webui.jsf.util.UploadFilter.doFilter(UploadFilter.java:267)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Thread.java:619)
```

aber das ist ja die nullpointer die eigentlich abgefangen werden soll.

mmmm!


----------



## HLX (2. Dez 2009)

Dann scheint das Framework die NullPointerException in einer eigenen Exception zu kapseln. Das der Tomcat anstelle der NullPointerException eine ApplicationException erhält, spricht er natürlich deine Error-Page nicht an.

[Edit]Ich kann dir allerdings nicht sagen, wie man das in JSF ändert. Vielleicht kannst du die ApplicationException in der web.xml angeben. Möglicherweise kommt die allerdings garnicht so weit durch.


----------

