`
liuwei1981
  • 浏览: 749943 次
  • 性别: Icon_minigender_1
  • 来自: 太原
博客专栏
F8258633-f7e0-30b8-bd3a-a0836a5f4de5
Java编程Step-by...
浏览量:155440
社区版块
存档分类
最新评论

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>

 

 

分享到:
评论
7 楼 bird_wang 2009-04-23  
如果一个jsp页面中包含有struts2的标签,那请求信息应该要经过Struts2的FilterDispatcher。个人觉得这点非常不方便,尤其是如果自定义Jsp Filter的话,那会有一大堆没办法解决的问题。
6 楼 jadesun 2008-12-16  
web.xml下配置

<filter>
  <filter-name>struts2</filter-name>
  <filter-class>
     org.apache.struts2.dispatcher.FilterDispatcher
  </filter-class>
  <init-param>
     <param-name>struts.action.extension</param-name>
     <param-value>action</param-value>
  </init-param>
</filter>
5 楼 liuwei1981 2008-12-16  
zhangqinqin 写道

我就默认配置的没有问题


Java代码

&lt;filter&gt; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-name&gt;struts2&lt;/filter-name&gt; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-class&gt;org.apache.struts2.dispatcher.FilterDispatcher&lt;/filter-class&gt; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/filter&gt; &nbsp;&nbsp;
&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-mapping&gt; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;filter-name&gt;struts2&lt;/filter-name&gt; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;url-pattern&gt;/*&lt;/url-pattern&gt; &nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/filter-mapping&gt;&nbsp;&nbsp;&lt;filter&gt;
        &lt;filter-name&gt;struts2&lt;/filter-name&gt;
        &lt;filter-class&gt;org.apache.struts2.dispatcher.FilterDispatcher&lt;/filter-class&gt;
    &lt;/filter&gt;

    &lt;filter-mapping&gt;
        &lt;filter-name&gt;struts2&lt;/filter-name&gt;
        &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
    &lt;/filter-mapping&gt;
我的jdk是1.5


我的意思是,在实际情况中不能使用这个默认配置,出现的问题如何解决
4 楼 zhangqinqin 2008-12-16  
我就默认配置的没有问题
<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>

我的jdk是1.5
3 楼 yu_xian81 2008-09-10  
在struts2下,任何包含struts2标签的jsp 页面都是不能直接访问的.必须经过action,struts2才会处理到该页面.
2 楼 liuwei1981 2008-07-22  
不好意思,struts2的过滤器配置,在实际配置中确实是<url-pattern>*.action</url-pattern> ,在文章里写错了,

另外,关于dtd文件的放置,第三种方法,我的jdk是1.5,dtd文件在META-INFO目录下,运行错误,

第二种方法,我将dtd文件直接放到web-inf目录下,配置文件也按照这个路径配置,还是运行错误
1 楼 congpeixue 2008-07-21  
1.
引用
<url-pattern>/*.action</url-pattern>  


你的这一句话 , 就有问题, 个人认为应该为
<url-pattern>*.action</url-pattern> 
否则会抛格式化不正确的异常。

2 .
引用
<taglib-location>/WEB-INF/struts2-core-2.0.11.jar</taglib-location>


应该为
    <jsp-config>
    	<taglib>
    	 	 <taglib-uri>struts-tags</taglib-uri>   
	 		 <taglib-location>/WEB-INF/struts2-core-2.0.11.jar/struts-2.0.dtd</taglib-location>   
	 	</taglib>  
    </jsp-config>


这样才能找到dtd的位置。

3 另一种解决办法
如果允许的话 , 你可以把dtd放在META-INFO目录下(前提, 你的jdk版本够高)

相关推荐

Global site tag (gtag.js) - Google Analytics