Struts2.1XX 后台不打印异常问题

   在开发的时候发现Struts2.16 在action内抛出异常的时候,控制台是没有打印信息的,不过在Struts2.0的版本却可以,还不知道为什么要去掉(暂时不去研究),但这样很不方面,特别是写AJax 调用的时候。。于是对源码分析了一下后,发现了问题的所在是ExceptionMappingInterceptor 的默认参数的logEnabled 是false的,而抛出错误的时候根据这个判断决定是否打印。。

 

 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> exceptionMappings = invocation.getProxy().getConfig().getExceptionMappings();
            String mappedResult = this.findResultFromExceptions(exceptionMappings, e);
            if (mappedResult != null) {
                result = mappedResult;
                publishException(invocation, new ExceptionHolder(e));
            } else {
                throw e;
            }
        }

        return result;
    }

 

 

了解了问题所在后,就知道怎么解决这个问题了。我的临时解决方案是在struts2的配置文件上加上下面:

<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>
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值