Hi, Ilya:

> But struts-2 breaks this scheme.
>
> 1) it does not pass exception to container so container can't log it.

I used struts2 for several years.
In our projects, struts-2 does not break this schema.

I have read the source of struts2. When an exception is thrown from
action execution, struts2 will catch it, and
(1)set 500 error to the response code
(2)put the exception instance into request attribute
[javax.servlet.error.exception] and [javax.servlet.jsp.jspException]

source code like this:

package org.apache.struts2.dispatcher;
class: Dispatcher

                // WW-1977: Only put errors in the request when code
is a 500 error
                if (code == HttpServletResponse.SC_INTERNAL_SERVER_ERROR) {
                    // send a http error response to use the servlet
defined error handler
                    // make the exception availible to the web.xml
defined error page
                    request.setAttribute("javax.servlet.error.exception", e);

                    // for compatibility
                    request.setAttribute("javax.servlet.jsp.jspException", e);
                }

                // send the error response
                response.sendError(code, e.getMessage());


you can handle exception by:
(1)add this setting into web.xml:
        <error-page>
                <exception-type>java.lang.Exception</exception-type>
                <location>/some_path/errorException.jsp</location>
        </error-page>
(2)create a errorException.jsp






2011/11/12 Ilya Kazakevich <ilya.kazakev...@jetbrains.com>:
> Hello,
>
> In bare container (tomcat) everything is good: Servlet throws exception and
> container logs it and displays 500 error page with certain status.
> Each uncounght exception should lead to 500 error because uncought exception
> is _program_ error.
>
> But struts-2 breaks this scheme.
>
> 1) it does not pass exception to container so container can't log it.
> 2) even if I use "exception" interceptor (ExceptionMappingInterceptor)
> struts does not set "500" error code to my result. So I have to set it in my
> JSP (or servlet) manually.
> I can't use static 500 error page as I did in tomcat.
>
> So, my questions are:
>
> 1) Why do not struts passes exception to container by default? Could I
> configure it to do so?
> 2) If struts can't do it -- how can I make it to send 500 status for my
> exception? I do not want to configure my jsp
> 3) Who really needs exeption handling in struts?  Somebody wants user to be
> redirected to different actions based on exception type? What for? Smells
> like exception-based business logic moved from java to struts.xml and does
> not look like good practice.
>
> I need to write a lot just to get back to default container behavior (500
> status and logging):
>
> 1) Create _new_ stack to set logEnabled and logLevel
> 2) Configure package to use it
> 3) Add global error result
> 4) Add global exception handling
> 5) Create JSP with "status 500" instead of my 500.html page
>
> Is not it too big for such simple task?
>
>
>
> Ilya Kazakevich,
> Developer
> JetBrains Inc
> http://www.jetbrains.com
> "Develop with pleasure!"
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to