3. Spring MVC sitemesh velocity Integration

Source: Internet
Author: User

Next http://blog.csdn.net/qust008/article/details/9623513

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

Create a general template first. All VMS returned from the background are embedded in this template.

Under webcontent, create the folder decorators and create a file template. VM under decorators. The content is as follows:


Create the file decorators. xml in the WEB-INF with the following content:

<? XML version = "1.0" encoding = "UTF-8"?> <Decorators defaultdir = "/decorators"> <! -- The page that does not need to be filtered is defined here --> <excludes> </Excludes> <! -- Defines the page to be filtered by the decorator --> <decorator name = "template" page = "template. VM "> <pattern>/user/getuser. DO </pattern> </decorator> </decorators>

Modify the springMvc-servlet.xml as follows

<? XML version = "1.0" encoding = "UTF-8"?> <! -- See the following beans this element label does not exist, must have a declaration of the label --> <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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springfr Renew http://www.springframework.org/schema/mvc/spring-mvc.xsd "> <! -- Scan all classes in the Web package to create beans and automatically inject dependencies --> <context: component-scan base-package = "qust. THB. * "/> <! -- Support spring3.0 new MVC annotation --> <MVC: annotation-driven/> <! -- Start the annotation function of spring MVC to map requests and pojo annotations --> <Bean class = "org. springframework. Web. servlet. MVC. annotation. annotationmethodhandleradapter"/> <! -- Add the prefix and suffix without view parsing --> <Bean class = "org. springframework. web. servlet. view. internalresourceviewresolver "> <property name =" prefix "value ="/WEB-INF/"/> <property name =" suffix "value = ". VM "/> </bean> </beans>

Modify web. XML as follows:

<? 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-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-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-Name> site-mesh-velocity </servlet-Name> <servlet-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-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 directory structure of the final project is as follows:

Access address http: // localhost: 8080/springmvc/user/getuser. Do

So far, the simple framework without database connection has been set up, source code


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.