Struts exceptions are not captured and can be output in the console and log files.

Source: Internet
Author: User

When Struts2.16 throws an exception in the action during development, the console does not print the information, but it can be used in the Struts2.0 version, I still don't know why I should remove it (I will not study it for the time being), but it is not very helpful, especially when I write AJax calls .. After analyzing the source code, we found that the default logEnabled parameter of predictionmappinginterceptor is false. When an error is thrown, we can determine whether to print it .. Java code protected boolean logEnabled = false; public String intercept (ActionInvocation invocation) throws Exception {String result; try {result = invocation. invoke ();} catch (Exception e) {if (isLogEnabled () {handleLogging (e);} www.2cto.com List <ExceptionMappingConfig> exceptionMappings = invocation. getProxy (). getConfig (). getExceptionMappings (); String mappedResult = this. findresultfrom0000t Ions (exceptionMappings, e); if (mappedResult! = Null) {result = mappedResult; publishException (invocation, new ExceptionHolder (e);} else {throw e ;}} return result;} [java] protected boolean logEnabled = false; public String intercept (ActionInvocation invocation) throws Exception {String result; try {result = invocation. invoke ();} catch (Exception e) {if (isLogEnabled () {handleLogging (e);} List <ExceptionMappingConfig> exceptionMap Pings = invocation. getProxy (). getConfig (). getExceptionMappings (); String mappedResult = this. findResultFromExceptions (exceptionMappings, e); if (mappedResult! = Null) {result = mappedResult; publishException (invocation, new ExceptionHolder (e);} after learning about the problem, else {throw e, you will know how to solve this problem. My temporary solution is to add the following to the struts2 configuration file: xml Code <interceptors> <interceptor-stack name = "default"> <interceptor-ref name = "exception"> <param name = "logEnabled"> true </param> <param name = "logLevel"> warn </param> </interceptor-ref> <interceptor-ref name = "defaultStack"> </interceptor-ref> </interceptor-stack> </interceptors> <default-interceptor-ref name = "default"> </default-interceptor-ref>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.