DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=28465>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=28465

Cannot use jsp error pages from servlets

[EMAIL PROTECTED] changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |



------- Additional Comments From [EMAIL PROTECTED]  2004-04-20 07:01 -------
Using error pages defined in web.xml <error-page> -element is not really an 
option for me. I need to use different error pages depending on the location of 
the page that generated the exception. Basically I have a dispatcher that 
searches for the correct error page from the parent directories of the page 
that generated the exception.

Use of the standard attribute (javax.servlet.error.exception) enables my error 
pages to take advantage of the standard jsp features such as having the 
implicit exception object defined in my error pages and the possibility to 
explicitly select the error page to be used by defining the errorPage page 
directive.

Invoking jsp error pages from servlets, dispatchers and such by first setting 
the standard attribute and then forwarding seems to be a common practise 
anyway. I have seen numerous examples where this has been done. For example the 
java pet store example (both version 1.3.2 from 
http://java.sun.com/developer/releases/petstore/ and version 1.4 that comes 
with j2ee 1.4) contains a servlet called 
com.sun.j2ee.blueprints.waf.controller.web.MainServlet which on error 
conditions sets the "javax.servlet.jsp.jspException" attribute and uses a 
dispatcher to forward to the error page it selects. To my understanding the pet 
store example is supposed to provide best practice guidelines.

>From the petstore:

    private void doProcess(HttpServletRequest request, HttpServletResponse 
response)
                   throws IOException, ServletException {
        // set the locale of the user to default if not set
        if (request.getSession().getAttribute(WebKeys.LOCALE) == null) {
            request.getSession().setAttribute(WebKeys.LOCALE, defaultLocale);
        }
        try {
                 getRequestProcessor().processRequest(request);
                 getScreenFlowManager().forwardToNextScreen(request,response);
        } catch (Throwable ex) {
            String className = ex.getClass().getName();
            String nextScreen = getScreenFlowManager().getExceptionScreen(ex);
            // put the exception in the request
            request.setAttribute("javax.servlet.jsp.jspException", ex);
            if (nextScreen == null) {
                // send to general error screen
                ex.printStackTrace();
                throw new ServletException("MainServlet: unknown exception: " + 
className);
            }
            context.getRequestDispatcher(nextScreen).forward(request, response);
      }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to