简体   繁体   中英

Configuring RunTimeException class in Struts2

My requirement is as follows. My application is built on Struts2 framework and using annotation plugin. When I get any RunTimeException I need to call a method of my custom class which prints error stack using e.printStackTrace() method. How can I configure this class in my application. I do not want to use try and catch block in each and every actions I have.

After getting error I want to display error.jsp to user. but in my tomcat console I would like to print error stack. Please let me know if anyone is having idea.

Thanks Peter

I am not sure about annotation since i have used it very limited but it can be done easily using struts.xml file with the help of ExceptionMappingInterceptor .

All you need to define custom stack for this and add few parameter to the xml file to let S2 handle the uncaught exception and at same time log that in the log file/console

<interceptors>
  <interceptor-stack name="appDefaultStack">
    <interceptor-ref name="defaultStack">
     <param name="exception.logEnabled">true</param>
     <param name="exception.logLevel">ERROR</param>
    </interceptor-ref>
 </interceptor-stack>
</interceptors>

<default-interceptor-ref name="appDefaultStack" />

For more details refer to exception-handling . I believe it can be easily converted to annotation based solution as annotation plugin provides all options what can be done in XML file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM