2009-08-28 73 views
0

我需要創建一個使用Struts2作爲MVC,Hibernate進行數據訪問的應用程序,並在業務邏輯中使用Spring。 而且我還需要使用Velocity for presentaion和sitemesh進行模板。Velocity + Struts2 + Sitemesh + Spring + Hibernate集成如何配置web.xml?

集成Hibernate和Spring很容易做到,但將spring,sitemesh和velocity與Struts2集成在一起對我來說並不是很清楚,但我可以在Struts2中單獨使用velocity,spring和sitemsh。

當然如在本示例中示出http://www.rkcole.com/articles/struts/crudTutorial/step4.html 的sitemesh和彈簧可以與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> 

被集成現在我的任務是速度與該組合整合....... ........

通常整合速度和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

回答

3

雅,最後我得到了很多的閱讀和搜索之後,這個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