struts标签错误The Struts dispatcher cannot be found.

 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]
 at org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60)
 at org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44)

  原本使用标签,引用方法是默认配置:

     web.xml:

  1. <filter>  
  2.   <filter-name>struts2</filter-name>  
  3.     <filter-class>  
  4.        org.apache.struts2.dispatcher.FilterDispatcher   
  5.     </filter-class>  
  6. </filter>  
  7.   
  8. <filter-mapping>  
  9.     <filter-name>struts2</filter-name>  
  10.     <url-pattern>/*</url-pattern>  
  11. </filter-mapping>  

    在页面中引用:

  1. <%@ taglib prefix="s" uri="/struts-tags"%>  

 

    由于在使用的web应用中一些特殊应用的关系,web.xml的配置改为:

  1. <filter>  
  2.   <filter-name>struts2</filter-name>  
  3.     <filter-class>  
  4.        org.apache.struts2.dispatcher.FilterDispatcher   
  5.     </filter-class>  
  6. </filter>  
  1. <taglib>  
  2.   <taglib-uri>struts-tags</taglib-uri>  
  3.   <taglib-location>/WEB-INF/struts2-core-2.0.11.jar</taglib-location>  
  4.  </taglib>  
  5.   
  6. <filter-mapping>  
  7.     <filter-name>struts2</filter-name>  
  8.     <url-pattern>/*.action</url-pattern>  
  9. </filter-mapping>  

    让sturts过滤器只接受后缀名为action的请求,并把struts标签配置到web.xml文件。  

    但在使用中,直接访问index.jsp,出现异常:

  1. The Struts dispatcher cannot be found.  This is usually caused by using Struts tags without the associated filter. Strut   
  2. s tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher n   
  3. eeded for this tag. - [unknown location]  

    在struts2中不能直接使用jsp,引用struts2的标签么?是否有解决的方法?

   找到解决方法了,其实只要再加一个过滤设置就可以了:

  1. <filter-mapping>  
  2.     <filter-name>struts2</filter-name>  
  3.     <url-pattern>*.jsp</url-pattern>  
  4. </filter-mapping>  
  1. <filter-mapping>  
  2.     <filter-name>struts2</filter-name>  
  3.     <url-pattern>/*.action</url-pattern>  
  4. </filter-mapping>  

 

你可能感兴趣的:(jsp,struts,servlet,filter,action,tags)