这是我在整合struts2,mybatis,spring时遇到的一些问题,在此分享出来,并记录下来供参考.
第一个问题和解决方式:
The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. 异常
异常信息: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.
-----这是由于添加了struts的标签后引起的
在web.xml的配置
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
默认是*.action过滤
引入struts标签后,出现这种异常,归纳以下有三种解决方法:
1:将web.xml下struts过滤器的过滤方式*.action改为/*;这样会默认对所有的进行过滤,自我感觉不是很好.
2:在页面不使用struts标签.
3:再加一个过滤方式
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
推荐使用第三个方式!!!