2009-08-28 72 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