Springmvc configures multiple views, returns jsp, velocity, freeMarker, tiles (Template), and so on, tilesvelocity

Source: Internet
Author: User

Springmvc configures multiple views, returns jsp, velocity, freeMarker, tiles (Template), and so on, tilesvelocity

Springmvc-servlet.xml Configuration

<! -- Velocity --> <bean id = "velocityViewResolver" class = "org. springframework. web. servlet. view. velocity. velocityViewResolver "> <property name =" order "value =" 0 "/> <property name =" contentType "value =" text/html; charset = UTF-8 "/> <property name =" requestContextAttribute "value =" req "/> </bean> <! -- Velocity --> <bean id = "velocityConfig" class = "org. springframework. web. servlet. view. velocity. velocitycycler "> <property name =" configLocation "value ="/WEB-INF/velocity. properties "/> <property name =" resourceLoaderPath "value ="/"/> </bean> <! -- FreeMarker --> <bean id = "freeMarkerViewResolver" class = "org. springframework. web. servlet. view. freemarker. freeMarkerViewResolver "> <property name =" order "value =" 0 "/> <property name =" viewClass "value =" org. springframework. web. servlet. view. freemarker. freeMarkerView "/> </bean> <! -- FreeMarker --> <bean id = "freemarkerConfig" class = "org. springframework. web. servlet. view. freemarker. freeMarkerConfigurer "> <property name =" configLocation "value ="/WEB-INF/freemarker. properties <property name = "templateLoaderPath" value = "/WEB-INF/ftl/"/> <property name = "freemarkerVariables"> <map> <entry key = "xml_escape" value-ref = "fmXmlEscape"/> </map> </property> </bean> <bean id = "fmXmlEscape" class = "freemarker. template. utility. xmlEscape "/>
  
<Bean id = "tilesViewResolver" class = "org. springframework. web. servlet. view. urlBasedViewResolver "> <property name =" viewClass "value =" org. springframework. web. servlet. view. tiles3.TilesView "> </property> <property name =" order "value =" 1 "/> </bean> <bean id =" tilesConfigurer "class =" org. springframework. web. servlet. view. tiles3.TilesConfigurer "> <property name =" definitions "> <list> <value> classpath: layout. xml </Value> </list> </property> </bean> <! -- Define the location of the JSP file --> <bean id = "viewResolver" class = "org. springframework. web. servlet. view. internalResourceViewResolver "> <property name =" prefix "value ="/WEB-INF/pages/"/> <property name =" suffix "value = ". jsp "/> <property name =" order "value =" 1 "/> </bean>

Note: Key <property name = "order" value = "1"/> Configure, 6 ...... first, it starts to parse from 0, and goes down in sequence. jsp must be placed at the end. Otherwise, the return page will be directly returned to the 404 page.

It won't match other pages, or set the order of jsp to the highest. This is a pitfall, or write your own Parser for parsing. That's easy.

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.