user2182326
user2182326

Reputation: 77

Exceptionhandling using Struts2 spring hibernate - best way to do it

i am programming a little webApplication with Struts2, Spring and Hibernate.

So I need to catch the 400 & 500 Errors and I dont want to show the Stacktrace.

So far I have an exceptionhandling for errors like "You cant delete a user if he still has a rental" as exceptionclass in my src folder. Is there a way to Display them in ONE jsp or do I need to made one jsp for each exception?

I have read about the <% page isErrorPage="true" %> but is it able to show all my exceptions? Or just the JSP exceptions like the 400 and 500 errors?

Hope you can understand my question and finding a solution would be even better :)

Thanks a lot!

Upvotes: 1

Views: 212

Answers (1)

Pratik Shelar
Pratik Shelar

Reputation: 3212

In your web.xml you can have the following configuration. So this will redirect all the general error codes which you want.

    <error-page>
    <error-code>500</error-code>
    <location>/WEB-INF/pages/serverErrorPage.jsp</location>
</error-page>
<error-page>
    <error-code>401</error-code>
    <location>/login/login.action</location>
</error-page>

Also in your struts.xml you can have a global exception mapping which can be a single error file.

   <global-results>
        <!--  standard error is an ajax error page -->
        <result name="exception">/WEB-INF/pages/error-ajax.jsp</result>
    </global-results>
   <global-exception-mappings>
        <exception-mapping exception="java.lang.Exception" result="exception" />
    </global-exception-mappings>

Upvotes: 2

Related Questions