struts 2 报错Could not find action or resul 常见错误原因分析

1.struts.xml配置的action与我们访问的action或返回的result确实没有匹配导致。这个时候要仔细检查Struts.xml配置文件;

2.我们的action输入正确,返回结果经过无数次查看都是对的,就是报找不到action或者没有对应的result结果,我们也有解决办法。这个时候很可能是没有编译上Struts.xml。查看项目下的struts.xml文件是否被编译上,有时我们分模块开发,细心检查自己的struts-xxx.xml是否被引入struts.xml中,即看你的struts.xml中是否通过include引入子模块的struts-xxx.xml文件。

3.确认配置没问题,这是很可能是因为表单的内容和Action类的字段类型不匹配,导致Action不执行execute而直接转到了input(原本我们想要success的),而此时你的Struts.xml没有定义相应的input,自然就是没结果了。此时应该检查类型的匹配,如果是自定义了类型转化器,则要检查xxx-conversion.properties配置文件是否正确,尤其是key名是否和Action的get和set方法匹配一致。这种情况错误一般如下:

No result defined for action com.lanhuigu.action.LoginAction and result input
    at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:364)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:266)
    at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
    at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
    at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
原文地址:https://www.cnblogs.com/JMLiu/p/8207006.html