web.xml error-pages are not working, why?

13,933

Well, for those that are strugling with this issue using Glassfish 3.1, you can handle that problem by following this article to the letter, even thought I changed at the end to use sendRedirect() instead of the JSF navigator to render the sessionexpired.xhtml file, but that's your choice, it works fine. Here you go:

http://weblogs.java.net/blog/edburns/archive/2009/09/03/dealing-gracefully-viewexpiredexception-jsf2

Share:
13,933
Joe Almore
Author by

Joe Almore

Updated on June 04, 2022

Comments

  • Joe Almore
    Joe Almore almost 2 years

    I'm running out of ideas by now, and don't know what else to try. The point is not even one error-page is working, I just would like to know, what am I doing wrong?, here is the code:

    <error-page>
        <exception-type>javax.faces.application.ViewExpiredException</exception-type>
        <location>/sessionexpired.xhtml</location>
    </error-page>
    <error-page>
        <error-code>500</error-code>
        <location>/500.xhtml</location>
    </error-page>
    

    When having this code in my web.xml I get this message:

    XML read error: no element found

    What this message means? how can I solve this? Thanks.

    BTW, I have also tried to use filters to handle the ViewExpiredException, then it works the first time when I send the POST message and redirects to the sessionexpired.xhtml. But if I click backward and then make the POST call again BAM! I get again the ViewExpiredException.

    UPDATE 30-NOV-2011 --[ALTERNATE SOLUTION]-------------------------------------

    After a while I found that in order to make it work you have to specify the loation to .html or .jsp files, so it would end up being:

    <error-page>
        <exception-type>javax.faces.application.ViewExpiredException</exception-type>
        <location>/sessionexpired.html</location>
    </error-page>
    <error-page>
        <error-code>500</error-code>
        <location>/500.jsp</location>
    </error-page>
    
  • Joe Almore
    Joe Almore over 12 years
    Hi SUMIT SINGH, thanks for your answer, but yes I already have error-page after the servlet-mapping. When I place the error-place clause it only throws the error "XML read error: no element found". What could be causing that?
  • BalusC
    BalusC over 12 years
    Ordering doesn't matter anymore since Servlet 2.4 (with XSD). Before that, Servlet 2.3 with DTD and older, ordering matters. But who is nowadays using an API older than 10 years?
  • Joe Almore
    Joe Almore over 12 years
    Hi BalusC, thanks for your answer but it's still not working. The URL pattern I have for FacesServlet is *.xhtml (as usual), the <location> of the <error-page> is the same as posted above in my question and it shows the same error in the browser with yellow background BTW.
  • BalusC
    BalusC over 12 years
    That error is browser specific. You seem to be using FF which indeed presents a XML error like that. Well, rightclick page and view source. What do you see? Is it empty? Or is it unparsed? Use Firebug and check request/response headers. What do they say? Especially the response content type.
  • Joe Almore
    Joe Almore over 12 years
    It's getting HTTP/1.1 500 Internal Server Error as result,and the source code of the result starts with <parsererror>. I have also tried to catch the error code 500 from the web.xml, but it's just useless, no error page is working from there. May be I should try using another machine, or something could be wrong with the installation of the Glassfish I use, I really don't know. It tries to catch error using the web.xml, but on its way another error is caused while parsing a XML File, that's all I know.
  • BalusC
    BalusC over 12 years
    Ah right, the error page template itself seems to contain a XHTML syntax error and Facelets felt over it while parsing it. Does that also happen when you open the error page directly by entering its URL in browser address bar? Can you try to edit your question to include the smallest possible but complete snippet of the error page which still reproduces the problem?
  • Joe Almore
    Joe Almore over 12 years
    Np, if I access directly from the URL the page (sessionexpire.xhtml) renders fine. As I told you this is solved using ExceptionHandlerFactory by now, until the people from Glassfish decide to release a fix to this version 3.1; I'll post the solution later. Thanks for your effort.
  • BalusC
    BalusC over 12 years
    Okay. I know how to create an exception handler (factory) though. It's only a bit a clumsy solution for this, but it's after all just a workaround.
  • Joe Almore
    Joe Almore over 12 years
    Yes, as you say, at least it's a decent workaround and solves the problem; at the end what matter most is to be able to continue working.
  • BalusC
    BalusC over 12 years
    Do you know that there's an ExternalContext#redirect() method? No more unnecessary javax.servlet imports anymore.
  • Sajib Acharya
    Sajib Acharya about 8 years
    My <error-page> tag resolves only *.jsp pages, and not *.html pages. Any idea, why this is happening?
  • Joe Almore
    Joe Almore about 8 years
    @SajibAcharya (not sure but) I think *.html are not processed by JSF, only *.jsp.