2. Integrate velocity with spring MVC

Source: Internet
Author: User

Next to the previous response

When spring MVC integrates velocity, it is necessary to introduce related packages. The packages to be imported are as follows:


Then, it is very simple configuration, then here, modify the content of the springMvc-servlet.xml, the content is modified 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"/> <! -- Viewresolver --> <! -- <Bean class = "org. springframework. web. servlet. view. internalresourceviewresolver "> <property name =" viewclass "value =" org. springframework. web. servlet. view. jstlview "/> <property name =" prefix "value ="/WEB-INF/"/> <property name =" suffix "value = ". JSP "/> </bean> --> <bean id =" velocityconfig "class =" org. springframework. web. servlet. view. velocity. velocitycycler "> <property name =" resourceloaderpath "value ="/WEB-INF/"/> <property name =" configlocation "value ="/WEB-INF/velocity. properties "/> </bean> <bean id =" viewresolver "class =" org. springframework. web. servlet. view. velocity. velocityviewresolver "> <property name =" cache "value =" true "/> <property name =" prefix "value =" "/> <property name =" suffix "value =". VM "/> </bean> </beans>

Then create the velocity. properties file in the WEB-INF folder, the content is very simple, just a few words

Input. Encoding = UTF-8
Output. Encoding = UTF-8

Delete hello. jsp in the view folder and create a new file named hello. VM. The content in the file is also very simple, as shown below:

<div>${message}</div>

Shows the overall directory structure.


Enter http: // localhost: 8080/springmvc/user/getuser. Do to access normal access

If velocity is used, sitemesh must be used for modification, so that we can create consistent page layout and appearance in a large number of page projects, such as consistent navigation bar, consistent banner, consistent copyright, etc.

Next introduction spring MVC uses sitemesh to modify Velocity

Http://blog.csdn.net/qust008/article/details/9625179

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.