Hi, I'd like to create and use my own exception handler in GlassFish 2. By default GlassFish uses the one predefined in web.xml: <servlet-mapping> <servlet-name>ExceptionHandlerServlet</servlet-name> <url-pattern>/error/ExceptionHandler</url-pattern> </servlet-mapping>
Does anyone know any tutorial on creating and applying my own exception handler (to GlassFish)? This might be considered a bad decision but I really need it.
Thanks a lot, I thought I would need to explicitly implement some kind of exception interface or method(s) with custom parameters, but in reality it turns out much simpler, you just create an usual servlet and change the web.xml file for errors to be sent to this servlet and what you do further is up to you.
Yeah I had a look at it but I don't need it, I only needed to catch the hideous Exception I get using Sun's JSF: when the session times out and the user clicks a submit-like button in a (JSF) form - the user gets a screen of errors and doesn't know what to do, I needed a way to catch that error and send the user to the main page in a user-friendly fashion. I tried to catch that Exception from "usual Java code" and nothing worked since the error raises inside the JSF implementation. I started thinking dropping JSF altogether or implementing my own exception handler. Luckily implementing it turned out to be much easier than I expected.
Originally posted by James Greenberg: Yeah I had a look at it but I don't need it, I only needed to catch the hideous Exception I get using Sun's JSF: when the session times out and the user clicks a submit-like button in a (JSF) form - the user gets a screen of errors and doesn't know what to do, I needed a way to catch that error and send the user to the main page in a user-friendly fashion. I tried to catch that Exception from "usual Java code" and nothing worked since the error raises inside the JSF implementation. I started thinking dropping JSF altogether or implementing my own exception handler. Luckily implementing it turned out to be much easier than I expected.
You want to handle ViewExpiredException? Just use the error-page directive of the web.xml for that.
thanks, I implemented your suggestion but the exception doesn't get caught by that page, but the servlet mentioned above does, so I'm happy that at least that one works.
It is the "production" version that Sun is pushing. I only know that it's not fixed for this version of GlassFish. As GlassFish 3 gets final I'm gonna move to that one, or perhaps use Tomcat. Is tomcat better than GlassFish when it comes to JSF.
You can just upgrade or replace the JSF version to whatever whenever you want. Mojarra even provides a Glassfish updater tool. Check their homepage: http://javaserverfaces.dev.java.net
About Tomcat v.s. Glassfish: I myself like Tomcat when it comes into development without the need for EJB's. Glassfish starts/restarts and debugs very slow, incredibly slow. Tomcat is small, lightweight and very quick. It starts and restarts within three seconds. But when EJB comes into picture, you may better consider JBoss AS, which is based on Tomcat, but has an EJB container on its top. Not as fast as Tomcat due to the EJB thing, but it's still faster than Glassfish.