<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
最近使用struts,在使用标签的时候,出现了这样一个问题。
原本使用标签,引用方法是默认配置:web.xml:
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/struts/*</url-pattern>
</filter-mapping>
在页面中引用struts标签:
<%@ taglib prefix="s" uri="/struts-tags"%>
然后点击下面链接访问页面:
//用户管理
$("#usersManage").click(function(){
$("#iframe").attr('src','sysconfig/userlist.jsp');
});
结果报错:
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.
原因是:如果想要在jsp文件中,采用 struts的tag,那么jsp必须是通过action跳转得到,也就是必须通过web.xml所配置的过滤器访问文件,否则会有异常。
解决方法:
在web.xml文件中添加一个对.jsp的过滤器,代码如下:
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/struts/*</url-pattern>
</filter-mapping>