求解:struts2标签的使用问题(不明确原因)

麥兜 发布于 2011/05/19 16:28
阅读 415
收藏 1

(1)web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
 xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 <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> 
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

(2)index.jsp中使用<%@ taglib uri="/struts-tags" prefix="s"%>

eg:http://localhost:8080/test/index.jsp

出现了:严重: Servlet.service() for servlet jsp threw exception
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中添加配置修改为

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
 xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 <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>
 <filter-mapping>
 <filter-name>struts2</filter-name>
 <url-pattern>*.jsp</url-pattern>
 </filter-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

在其中我只加了一个配置就没出错了

eg:<filter-mapping>
 <filter-name>struts2</filter-name>
 <url-pattern>*.jsp</url-pattern>
 </filter-mapping>
疑惑:为什么非得这样呢 还是说我这样写也只是碰巧的 至于struts2标签库的引用

甚是不明确 不明确这一步所促发的是什么 描述了什么

希望大哥们 教教我 !!!!帮我解决这个疑问!!!

谢谢!!

加载中
0
吴吴吴
吴吴吴

你就这样配就可以了

  <filter-mapping>
   <filter-name>struts2</filter-name>
   <url-pattern>/*</url-pattern>
  </filter-mapping>

返回顶部
顶部