zoukankan      html  css  js  c++  java
  • struts2没有打印日志原因和No result defined for action XXXAction and result input

    在项目中调用一个action的方法的时候发生了一个错误,但是在catalina.out和配置的log4j都没有打印异常,后来在执行的action中加了logger.error("XXXXX"),也没有打印异常。

    后来发现是struts2默认的有异常拦截器ExceptionMappingInterceptor,但是是禁用的,需要自己启用

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

    自定义全局异常处理的显示的页面

            <global-results>
                <result name="error">/public/error.jsp</result>
            </global-results>
    
            <global-exception-mappings>
                <exception-mapping result="error" exception="java.lang.Exception"></exception-mapping>
            </global-exception-mappings>

    在显示的页面/public/error.jsp也可以显示发生的异常信息

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@taglib uri="/struts-tags" prefix="s"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>
        <div class="msgFalse" >
            <dl>
                <dt>操作失败</dt>
            </dl>
            
            <s:property value="exception"/>
            <s:property value="exceptionStack"/>
        </div>
    </body>
    </html>

    异常:No result defined for action XXXAction and result input

    1.在action里面定义了某类型的变量,然后想通过struts的自动填装把post来的表单的数据转换,如果转换类型失败就出现此种错误

    2.页面提交了同一个名字的参数多个

    比如“”
    username 123
    username 123
    permissions 123
    info 31234
    页面提交了了两个username ,而我的后台却只写了一个String username,这样同样会出错.

    3.页面中用到的控件名称与后台Action中的属性名称不一致

    这个很好理解,名称不匹配,Struts2是不会给Action中的属性赋值的

  • 相关阅读:
    在JavaScript中对HTML进行反转义
    JavaScript 删除数组中的对象
    CSS中的before和:after伪元素深入理解
    关于css浮动的一点思考
    前端常见跨域解决方案(全)
    window.location对象详解
    51nod 1001 数组中和等于K的数对
    51nod 1002 数塔取数问题
    51nod 1015 水仙花数
    51nod 1080 两个数的平方和
  • 原文地址:https://www.cnblogs.com/grasp/p/11168603.html
Copyright © 2011-2022 走看看