【问题标题】:Velocity + Struts2 + Sitemesh + Spring +Hibernate Integration How to configur web.xml?Velocity + Struts2 + Sitemesh + Spring +Hibernate 集成 如何配置web.xml?
【发布时间】:2010-11-23 18:47:00
【问题描述】:

我需要创建一个使用 Struts2 作为 MVC、Hibernate 用于数据访问和业务逻辑中的 spring 的应用程序。 而且我还需要使用 Velocity 进行演示,使用站点网格进行模板。

集成 Hibernate 和 Spring 很容易,但是将 spring、sitemesh 和 velocity 与 Struts2 集成在一起 我不清楚,但我可以在 Struts2 中单独使用速度、弹簧和 sitemsh。

当然如本例所示http://www.rkcole.com/articles/struts/crudTutorial/step4.html sitemesh和spring可以与struts2集成配置web.xml为

<listener> 
<listener-class> 
org.springframework.web.context.ContextLoaderListener 
</listener-class> 
</listener> 

<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> 
<dispatcher>FORWARD</dispatcher> 
</filter-mapping> 

现在我的任务是将速度与这个组合整合起来......

通常集成 Velocity 和 struts2 我使用以下

<servlet-class> 
org.apache.velocity.tools.view.servlet.VelocityViewServlet 
</servlet-class> 
<load-on-startup>10</load-on-startup> 
</servlet> 
<servlet-mapping> 
<servlet-name>velocity</servlet-name> 
<url-pattern>*.vm</url-pattern> 
</servlet-mapping> 

.................................................. ...................................

现在我的问题是如何设置`

 <servlet-mapping>

`,它仅用于速度,或 simemesh 或必须设置不同

请让我知道如何继续,如果可以请回复完整的 web.xml 和其他要遵循的步骤。

问候

T.Thamilvaanan

【问题讨论】:

    标签: struts2


    【解决方案1】:

    是啊,经过大量的阅读和搜索,我终于得到了这个web.xml............

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    
    
    <!-- A part in Spring Integration-->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>
    </context-param>
    
    
    
    <!-- All the filters starts here-->
    
    <filter>
        <filter-name>struts-cleanup</filter-name>
        <filter-class>org.apache.struts2.dispatcher.StrutsPrepareFilter</filter-class>
    </filter>
    
    
    <!-- This is used to integrate sitemesh with Struts2-->
    
    <!-- 
    I am using Velocity to create sitemesh decorators so I have to use 
    
      VelocityPageFilter    to integrate
    
      Sitemesh  (i.e. Sitemesh in velocity)  +  Struts2    
    In the web.xml, the VelocityPageFilter should be placed between the
      ActionContextCleanUp (StrutsPrepareFilter since 2.1.3  )  and
    and the    FilterDispatcher (StrutsExecuteFilter  since 2.1.3)  
     -->
    
    <filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>org.apache.struts2.sitemesh.VelocityPageFilter</filter-class>
    </filter>
    
    <filter>       
    <filter-name>struts2</filter-name>   
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class> 
    </filter> 
    
    <filter-mapping>
    <filter-name>struts-cleanup</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <filter-mapping>
     <filter-name>sitemesh</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <filter-mapping>
        <filter-name>struts</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    
    
    <!-- Spring Integration-->
     <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    
    
    
        <!--Finally since I am velocity pages in struts2 MVC I am using
     VelocityViewServlet        to Integrate struts2 with Velocity  -->
    
      <servlet>
      <servlet-name>velocity</servlet-name>
      <servlet-class>org.apache.velocity.tools.view.VelocityViewServlet
      </servlet-class>
      <init-param>
        <param-name>org.apache.velocity.toolbox</param-name>
        <param-value>/WEB-INF/tools.xml</param-value>
      </init-param>
       <init-param>
        <param-name>org.apache.velocity.properties</param-name>
        <param-value>/WEB-INF/velocity.properties</param-value>
      </init-param>
      </servlet>
    
    
    <!-- Map *.vm files to Velocity -->
    <servlet-mapping>
      <servlet-name>velocity</servlet-name>
      <url-pattern>*.vm</url-pattern>
    </servlet-mapping>
    
    
    
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
    
    
        <welcome-file-list>
            <welcome-file>index.vm</welcome-file>
        </welcome-file-list>
    
    
       </web-app>
    

    希望这很好,将测试并让您知道。

    干杯…………

    问候

    Thamilvaanan

    【讨论】:

      猜你喜欢
      • 2017-02-25
      • 1970-01-01
      • 2015-10-31
      • 2012-11-13
      • 2013-01-24
      • 2012-12-29
      • 2012-11-30
      • 1970-01-01
      • 2010-12-24
      相关资源
      最近更新 更多