6 Replies Latest reply on Jul 23, 2012 8:02 AM by tremal_naik

    Bad redirection with tag <error-page> in web.xml

    tremal_naik

      Hi,

       

      I have the next section in my web.xml

       

      <error-page>

        <error-code>400</error-code>

                  <location>/error/errorPage.xhtml</location>

      </error-page>

      ...

      <error-page>

        <exception-type>java.lang.Exception</exception-type>

        <location>/error/errorPage.xhtml</location>

      </error-page>

       

      When my application has a Java Error like java.lang.NumberFormatException: For input string: "a" the error page is loaded into the page that generates the error like a new <div> instead of redirect it.

       

      Working with FireBug I have found the next package

       

      Request URL: http://localhost...page.xhtml/javax.faces.resource/jquery.js

      Request Method: GET

      Status Code: 404 Not found

       

      I has tried too with a Filter class, but the error is the same. Some idea? Thx!

       

      PS: The correct URL would be http://localhost.../javax.faces.resource/jquery.js.xhtml

        • 1. Re: Bad redirection with tag <error-page> in web.xml
          healeyb

          You're using suffix mapping rather than prefix mapping I imagine, i.e.

           

          <servlet-mapping>

                  <servlet-name>FacesServlet</servlet-name>

                  <url-pattern>*.xhtml</url-pattern>

          </servlet-mapping>

           

          rather than:

           

          <servlet-mapping>

                  <servlet-name>FacesServlet</servlet-name>

                  <url-pattern>/pages/*</url-pattern>

          </servlet-mapping>

           

          and the FacesServlet confusingly appends the suffix mapping to resources URLs despite the fact that this does

          not correspond to the filename.

           

          I imagine you're seeing the facelets development mode error page. You need to find out what's sending the GET

          request for jquery.js, presumably it's something in errorPage.xhtml (or a template), do you see a GET for

          errorPage.xhmtl in firebug?

           

          One thing that could trigger this behavior is if you used a script tag to load jquery instead of h:outputScript, but

          check out what's trying to load jquery first and perhaps post the contents of the errorPage.

           

          I remember having loads of problems with this sort of thing before switching to prefix mapping (which was not a

          straightforward exercise involving much changing of css files, filters, resource handlers you name it etc...).

           

          Regards,

          Brendan.

          1 of 1 people found this helpful
          • 2. Re: Bad redirection with tag <error-page> in web.xml
            tremal_naik

            Hi Brendan,

             

            Your reply is very useful. Using the FireBug there's not a GET por errorPage.xhtml but, this page has a template which invoques <h:outputScript name="jquery.js"/>.

             

            And I have

             

            <servlet-mapping>

              <servlet-name>Faces Servlet</servlet-name>

                                <url-pattern>*.faces</url-pattern>

                                <url-pattern>*.jsf</url-pattern>

                                <url-pattern>*.xhtml</url-pattern>

            </servlet-mapping>

             

             

            I'll try change the web.xml and discover how avoid this annoying suffix. Thanks.

            • 3. Re: Bad redirection with tag <error-page> in web.xml
              healeyb

              <h:outputScript name="jquery.js"/> will load the richfaces packaged jquery and I just checked a backup and when I

              was using suffix mapping that was all I specified. Is the h:outputScript tag in the h:head section of the template? I also

              had this in web.xml:

               

              <context-param>

                      <param-name>javax.faces.DEFAULT_SUFFIX</param-name>

                      <param-value>.xhtml</param-value>

              </context-param>

              <context-param>

                      <param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>

                      <param-value>*.xhtml</param-value>

              </context-param>

               

              Presumably the FACELETS_VIEW_MAPPINGS can be a comma separated list (prob described in the Mojarra FAQ).

               

              Using prefix mapping, i.e.

               

              <servlet-mapping>

                      <servlet-name>FacesServlet</servlet-name>

                      <url-pattern>/faces/*</url-pattern>

              </servlet-mapping>

               

              gets rid of the suffix, but does mean that you have a prefix in your URLs which is also a bit annoying. If you front your app server

              with Apache you can use mod_rewrite to get rid of it.

               

               

              Regards,

              Brendan.

              • 4. Re: Bad redirection with tag <error-page> in web.xml
                tremal_naik

                Hi Brendan,

                 

                I was tried your solutions but the problem persists... Maybe the error is elsewhere. I keep trying.

                 

                Thanks!

                • 5. Re: Bad redirection with tag <error-page> in web.xml
                  healeyb

                  Find somewhere that jquery.js loads ok, is it using jquery.js.xhtml or jquery.js? what's the difference in the page where it

                  loads ok, and the one where it doesn't.

                   

                  I'm not clear which page is loading that results in the error message. In firebug even if a page references a template you

                  would see the page loading with a GET or POST.

                  • 6. Re: Bad redirection with tag <error-page> in web.xml
                    tremal_naik

                    Hi,

                     

                    The template is called like this:

                     

                    <ui:composition template="/template.xhtml">

                     

                    My template have the next line

                     

                    <h:outputScript name="jquery.js"/>

                     

                    The FireBug shows that the request has been with a GET.

                     

                    A correct request is like this: http://localhost.../javax.faces.resource/script.js.xhtml

                     

                    When the page do not generates an error, the query.js.xhtml is loaded correctly