读书人

请问:sitemesh怎么装饰Struts 2中的ac

发布时间: 2012-03-01 10:25:47 作者: rapoo

请教:sitemesh如何装饰Struts 2中的action的问题
本人现在程序中存在的问题:
使用sitemesh进行装饰所有页面,但是当请求是Struts的action(例如*.do,*.action)时,就不能装饰.
注:现在所有的.jsp 和.action都在应用根目录下.
配置文件如下:
decorators.xml

XML code
<decorators defaultdir="/">    <decorator name="frame" page="template.jsp">        <pattern>/*</pattern>    </decorator></decorators>

web.xml
XML code
<!-- SiteMesh -->    <filter>        <filter-name>sitemesh</filter-name>        <filter-class>            com.opensymphony.module.sitemesh.filter.PageFilter        </filter-class>    </filter>    <filter-mapping>        <filter-name>sitemesh</filter-name>        <url-pattern>/*</url-pattern>    </filter-mapping>        <jsp-config>        <taglib>            <taglib-uri>sitemesh-page</taglib-uri>            <taglib-location>                /WEB-INF/sitemesh-page.tld            </taglib-location>        </taglib>        <taglib>            <taglib-uri>sitemesh-decorator</taglib-uri>            <taglib-location>                /WEB-INF/sitemesh-decorator.tld            </taglib-location>        </taglib>    </jsp-config>


struts.xml
XML code
        <action name="car" class="struts.action.Car_jsp_Action">            <result name="success">car.jsp</result>            <result name="input">car.jsp</result>        </action>

请问:
1:有没有办法让sitemesh也能装饰.action的请求页面.
2:sitemesh处理资源的原理是怎样的呢,对于.jsp .jpg .js .html .do .action .css的装饰是如何选择的.

[解决办法]
这个问题。。。呵呵 我刚开始弄的时候,也碰到过这个问题。。。
问题出现在那里列?

默认情况下,filter 的拦截范围是:reuqest,也就是说只会对请求进行拦截,这个就包括了重定向redirect,因为redirect是重新请求一次服务器。 而你的forward转发方式,拦截器就拦截不到。因为他是服务器部定向,没有重新发请求。。

好了,既然我们知道了问题的所在,那就开始解决问题吧:
打开web.xml配置如下:
XML code
 <filter-mapping>        <filter-name>sitemesh</filter-name>        <url-pattern>*.jsp</url-pattern>         <dispatcher>FORWARD</dispatcher>            <dispatcher>REQUEST</dispatcher>       </filter-mapping> 

读书人网 >J2EE开发

热点推荐