SpringMvc sitemesh freemarker integration summary, springmvcsitemesh
Preface
- I personally like springmvc's perfect support for restful, coupled with simple configuration and natural integration with spring, so the project intends to use springMvc;
- Freemarker has many evaluations on the Internet, but its performance is not crowded, but it is sufficient for the environment of our project. It is also very convenient to add its rich built-in functions and instructions;
- As for sitemesh, simple configuration is sufficient for small and medium-sized projects;
Configuration
The configuration of web. xml is as follows:
<Context-param> <param-name> contextConfigLocation </param-name> <param-value> classpath: spring/applicationContext. xml </param-value> </context-param> <listener-class> org. springframework. web. context. contextLoaderListener </listener-class> </listener> <filter-name> encodingFilter </filter-name> <filter-class> org. springframework. web. filter. characterEncodingFilter </filter-class> <Sync-supported> true </async-supported> <init-param> <param-name> encoding </param-name> <param-value> UTF-8 </param-value> </init-param> <param-name> forceEncoding </param-name> <param-value> true </param-value> </init-param> </filter> <filter-name> sitemesh </filter-name> <filter-class> com. opensymphony. sitemesh. webapp. siteMeshFilter </filter-class> <async-supported> true </async-supported> </Filter> <! -- Encoding --> <filter-mapping> <filter-name> encodingFilter </filter-name> <url-pattern>/* </url-pattern> </filter-mapping> <! -Sitemesh -->
<Filter-mapping> <filter-name> sitemesh </filter-name> <url-pattern>/* </url-pattern> </filter-mapping> <! -Springmvc --> <servlet-name> springServlet </servlet-name> <servlet-class> org. springframework. web. servlet. dispatcherServlet </servlet-class> <init-param> <param-name> contextConfigLocation </param-name> <param-value> classpath: /spring/springMvc/spring_mvc_base.xml </param-value> </init-param> <load-on-startup> 1 </load-on-startup> </servlet> <! -Freemarker configuration -->
<Servlet> <servlet-name> sitemesh-freemarker </servlet-name> <servlet-class> com. opensymphony. module. sitemesh. freemarker. freemarkerDecoratorServlet </servlet-class> <init-param> <param-name> TemplatePath </param-name> <param-value>/</param-value> </init- param> <init-param> <param-name> default_encoding </param-name> <param-value> UTF-8 </param-value> </init-param> <load- on-startup> 2 </load-on-startup> </servl Et> <servlet-mapping> <servlet-name> springServlet </servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <! -Freemarker page configuration -->
<servlet-mapping> <servlet-name>sitemesh-freemarker</servlet-name> <url-pattern>*.htm</url-pattern> </servlet-mapping>
Spring mvc and spring configurations do not need to be discussed;
Here, there are two places;
Summary
Finally, you need to think more, debug more, and understand the problems you encounter.