Struts2标签问题-using Struts tags without the associat

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

     最近使用struts,在使用标签的时候,出现了这样一个问题。

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

     web.xml:

     

<filter>
  <filter-name>struts2</filter-name>
    <filter-class>
       org.apache.struts2.dispatcher.FilterDispatcher
    </filter-class>
</filter>

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

     在页面中引用:

  

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

 

 

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

<filter>
  <filter-name>struts2</filter-name>
    <filter-class>
       org.apache.struts2.dispatcher.FilterDispatcher
    </filter-class>
</filter>
<taglib>
  <taglib-uri>struts-tags</taglib-uri>
  <taglib-location>/WEB-INF/struts2-core-2.0.11.jar</taglib-location>
 </taglib>

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

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

  

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

   

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

 

   在struts2中不能直接使用jsp,引用struts2的标签么?是否有解决的方法?希望大家能不吝赐教!

 

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

  

<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>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值