struts2 The Struts dispatcher cannot be found异常解决办法

来源:互联网 发布:软件开发相关书籍 编辑:程序博客网 时间:2024/06/05 03:37

HTTP Status 500 - The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]


一、原因

出现这个原因一般是web.xml文件配置出现问题,

<filter>    <filter-name>struts</filter-name>    <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class></filter><filter-mapping>    <filter-name>struts</filter-name>    <url-pattern>*.action</url-pattern></filter-mapping>

   这样配置以后,struts2只拦截以.action结尾的请求,而在页面中使用了struts的标签,没有被struts拦截,所以,标签不能被解析,就会报错。

二、解决办法

就是让struts2拦截页面的请求。最简单粗暴的方法就是拦截所有的请求。

<filter>    <filter-name>struts</filter-name>    <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class></filter><filter-mapping>    <filter-name>struts</filter-name>    <url-pattern>/*</url-pattern></filter-mapping>

0 0
原创粉丝点击