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