3. Spring MVC Sitemesh Velocity Integration

Source: Internet
Author: User
Tags xmlns

Pick up an article on http://blog.csdn.net/qust008/article/details/9623513

This configuration still needs to import the package, the newly imported package is commons-beanutils-1.7.0,sitemesh-2.4.2,velocity-tools-view-2.0

Create a generic template and the VMS returned in the background are embedded in this template

Under WebContent, create a new folder decorators, create a new file TEMPLATE.VM under Decorators, with the following

Create a new file Decorators.xml under Web-inf, with the following content

<?xml version= "1.0" encoding= "UTF-8"?> <decorators
defaultdir= "/decorators" >
    <!-- This defines pages that do not need to be filtered-
    <excludes>
        
    </excludes>
    
    <!--here to define the page that the adorner needs to filter--
    < Decorator name= "template" page= "TEMPLATE.VM" >
        <pattern>/user/getUser.do</pattern>
    </ Decorator>
</decorators>

To modify the Springmvc-servlet.xml, the contents are as follows

<?xml version= "1.0" encoding= "UTF-8"?> <!--see below beans this element tag is not, must have label declaration--<beans xmlns= "/http/ Www.springframework.org/schema/beans "xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "xmlns:context=" http ://www.springframework.org/schema/context "xmlns:mvc=" Http://www.springframework.org/schema/mvc "xsi: schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring -mvc.xsd > <!--scan all classes in a Web package to complete bean creation and automatic dependency injection-<context:component-scan base-package= "qust.thb.* "/> <!--support spring3.0 new MVC annotations--<mvc:annotation-driven/> <!--start the Spring MVC Annotation feature, complete the mapping of request and annotation Pojo--&
    Gt <bean class= "Org.springframework.web.servlet.mvc.annotation.AnnotationMEthodhandleradapter "/> <!--just add prefix, suffix, without view resolution--<bean class=" Org.springframework.web.servlet.view.InternalResourceViewResolver "> <property name=" prefix "value="/web-inf /"/> <property name=" suffix "value=". VMs "/> </bean> </beans>
Modify Web. XML with the following content

<?xml version= "1.0" encoding= "UTF-8"?> <web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xmlns:web= "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi: schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id= "Webapp_ ID "version=" 3.0 "> <display-name>SpringMVC</display-name> <!--sitemesh configuration--<filter> &L T;filter-name>site-mesh</filter-name> <filter-class>
		Com.opensymphony.module.sitemesh.filter.pagefilter</filter-class> </filter> <filter-mapping> <filter-name>site-mesh</filter-name> <url-pattern>/*</url-pattern> </filter-mapping > <servlet> <servlet-name>springMvc</servlet-name> <servlet-class> Org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</ Load-on-startup> </servlet> <!--sitemesh servlet configuration-<servlet> <servlet-name>site-mesh-velocity</servlet-name> <servle T-class>com.opensymphony.module.sitemesh.velocity.velocitydecoratorservlet</servlet-class> < load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name> Springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> < Servlet-mapping> <servlet-name>site-mesh-velocity</servlet-name> <url-pattern>*.vm</ url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</ welcome-file> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
The final project directory structure is as follows


Access Address http://localhost:8080/SpringMVC/user/getUser.do can


At this point, a simple framework without a connection to the database is set up, source download address

http://download.csdn.net/detail/qust008/5838407

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.