速度 + Struts2 + Sitemesh + Spring +Hibernate 集成 如何配置 web.xml?

发布于 2024-08-03 17:15:09 字数 1725 浏览 2 评论 0原文

我需要创建一个应用程序,使用 Struts2 作为 MVC,使用 Hibernate 进行数据访问,并在业务逻辑中使用 Spring。 我还需要使用 Velocity 进行演示,使用 sitemesh 进行模板化。

集成 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与这个组合集成............

通常要集成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

I needed to create an application using Struts2 as MVC,Hibernate for data access and spring in the business logic.
And also I needed to use Velocity for presentaion and sitemesh for templating.

Integrating Hibernate and Spring is done easily but integrating spring, sitemesh and velocity together with Struts2
is not clear for me but I can use velocity,spring and sitemsh individually with Struts2.

Of course as illustrated in this example http://www.rkcole.com/articles/struts/crudTutorial/step4.html
sitemesh and spring can be integrated with struts2 configuring web.xml as

<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> 

Now my task is to integrate velocity with this combination...............

Normally to integrate Velocity and struts2 I use the following

<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> 

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

Now my question is how to set `

 <servlet-mapping>

`, its only for velocity, or simemesh or has to be set differently

Please let me know how to proceed,if can please reply with complete web.xml and others steps to be followed.

Regards

T.Thamilvaanan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眉黛浅 2024-08-10 17:15:09

是的,经过大量阅读和搜索,我终于得到了这个 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

Ya, finally I got this web.xml after lots of reading and searching............

<?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>

Hope this is fine,will test and let you know.

Cheers............

Regards

Thamilvaanan

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文