Struth2过滤报错“警告: Could not find action or result”解决办法
2014-11-30 14:00
459 查看
用Struth2框架时,如果浏览器中输入了struth.xml中没有定义的action时,会报以下错误:
警告: Could notfind action or result
There is no Action mapped for namespace /and action name dawdwadwaad. - [unknown location]
警告: Could notfind action or result
There is no Action mapped for action namehtml. - [unknown location]
网上找了一下有以下几种解决办法,供参考
第一种方法:
第二种方法:
类似第一种方法,只是没用全局跳转,而是在DefaultAction中加个execute()方法,直接return "xxxx";
public String execute(){
return "xxxx";//xxxx自己随便定义,只要跟struth.xml定义的一样就行
}
struth.xml中配置:
第三种方法:
第四种方法:
我用的第二种方法,其他的自己看想用哪个用哪个,方法百度上找的。
警告: Could notfind action or result
There is no Action mapped for namespace /and action name dawdwadwaad. - [unknown location]
警告: Could notfind action or result
There is no Action mapped for action namehtml. - [unknown location]
网上找了一下有以下几种解决办法,供参考
第一种方法:
<!-- 这句话意思就是你说的了,只要找不到action,都会找这个默认的action--> <default-action-ref name="defaultAction" /> <!-- 配置全局result,因为你的action直接返回error,所以我们添加一个全局的result,用来指示错误以后,返回哪个页面。 --> <global-results> <result name="error" type="redirect">page/error.jsp</result> //里面的路径和JSP文件你自己写。 </global-results> <!-- 默认action -->这一步是把你写的那个action配置到struts中。 <action name="defaultAction" class="前面加你的包名DefaultAction" />
第二种方法:
类似第一种方法,只是没用全局跳转,而是在DefaultAction中加个execute()方法,直接return "xxxx";
public String execute(){
return "xxxx";//xxxx自己随便定义,只要跟struth.xml定义的一样就行
}
struth.xml中配置:
<default-action-ref name="defaultAction" /> <!-- 默认action -->这一步是把你写的那个action配置到struts中。 <action name="defaultAction" class="前面加你的包名 DefaultAction" > <result name="XXXX">要跳转的jsp,如login.jsp</result> </action>
第三种方法:
<struts> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index"></default-action-ref> <action name="index"> <result>/default.jsp</result> </action> </package> </struts>
第四种方法:
不管action还是页面,如果找不到,都会报404错误,那么在你的项目的web.xml中配置一下,让所有404错误都跳转到你指定的页面(比如你定义一个error.jsp页面),就OK了,配置如下: <!-- 配置404错误时转向到的页面 --> <error-page> <error-code>404</error-code> <location>/error.jsp</location> </error-page>
我用的第二种方法,其他的自己看想用哪个用哪个,方法百度上找的。
相关文章推荐
- Strust2 中 Could not find action or result 原因分析及解决办法
- Strust2 中 Could not find action or result 原因分析及解决办法
- [struts2学习笔记] 第六节 struts2依赖的jar包还有Could not find action or result 错误解决
- struts2的配置之could not find action or result 问题的解决方法(struts.xml文件路径)
- 警告: Could not find action or result
- 警告: Could not find action or result 的原因
- 警告: Could not find action or result There is no Action mapped for namespace [/] and action name [] a
- Struts2的配置中:Could not find action or result 问题的解决方法
- 警告: Could not find action or result There is no Action mapped for namespace / and action name
- Struts2 Could not find action or result的解决方法
- Struts2的配置中:Could not find action or result 问题的解决方法
- Struts2的配置中:Could not find action or result 问题的解决方法
- [struts2学习笔记] 第六节 struts2依赖的jar包还有Could not find action or result 错误解决
- Struts2的配置中:Could not find action or result 问题的解决方法
- [struts2学习笔记] 第六节 struts2依赖的jar包还有Could not find action or result 错误解决
- 警告: Could not find action or result
- Could not find action or result,There is no Action mapped for namespace / and action name hello_struts. - [unknown location]
- Could not find action or result
- 报错:Could not find action or result
- Could not find action or result问题