按照网上的教程试验了一下,在index.jsp文件中使用struts2标签,总是报错:
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>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的访问,需要把.jsp也交给控制器处理才能正确使用struts标签。解决方法就是在web.xml加入以下配置:
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
参考:http://blog.csdn.net/guoquanyou/article/details/6585847