SPRINGMVC configuring JSON, JSP, Freemark Multi-View parser configuration

Source: Internet
Author: User

1.web.xml content:

<?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 ">    <context-param>         <param-name>contextConfigLocation</param-name>         <param-value>classpath:beans.xml</param-value>     </context-param>            < listener>                 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>     </listener>    <!--dealing with memory leaks caused by the use of introspection APIs-->    <listener>         <listener-class> org.springframework.web.util.introspectorcleanuplistener</listener-class>    </ Listener><filter>    <filter-name>characterencodingfilter</filter-name >    <filter-class>org.springframework.web.filter.characterencodingfilter</ filter-class>    <init-param>           <param-name>encoding</param-name>           <param-value>utf-8</param-value>      </init-param >     <init-param>           <param-name>forceencoding</param-name>          <param-value>true</param-value>       </init-param>  </filter><filter-mapping>    < filter-name>characterencodingfilter</filter-name>    <url-pattern>/*</ url-pattern></filter-mapping><servlet>    <servlet-name>springmvc< /servlet-name>    <servlet-class> Org.springframework.web.servlet.dispatcherservlet</servlet-class>    <init-param >        <param-name>contextConfigLocation</param-name>         <param-value>classpath:Servlet.xml</param-value>     </init-param>    <load-on-startup>1</ Load-on-startup></servlet><servlet-mapping>    <seRvlet-name>springmvc</servlet-name>    <url-pattern>/</url-pattern> </servlet-mapping><welcome-file-list>    <welcome-file>index.html</ Welcome-file>    </welcome-file-list></web-app>

2.servlet.xml content:

<?xml version= "1.0"  encoding= "UTF-8"? ><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/beans                            http://www.springframework.org/schema/beans/spring-beans-3.2.xsd                  http:// www.springframework.org/schema/context                  http://www.springframework.org/schema/context/spring-context-3.2.xsd                 http://www.springframework.org/schema/mvc                  http://www.springframework.org/ Schema/mvc/spring-mvc-3.2.xsd ">                 <!--  Component Auto-scan  -->            <context:component-scan base-package= "Com.tliu.case2.web"/>            <!--primarily acts on @controller activates the pattern below is a shorthand form             it will automatically register defaultannotationhandlermapping with annotationmethodhandleradapter,            is required for SPRING&NBSP;MVC to distribute the request for @controllers    - ->                            <mvc:annotation-driven/>           <!--  Configure JSON view  -->     <bean id= " Mappingjacksonhttpmessageconverter " class=" Org.springframework.http.converter.json.MappingJacksonHttpMessageConverter ">      <property name= "Supportedmediatypes" >     <list>      <value>application/json;charset=utf-8</value>     </list >     </property>           <property name= "Objectmapper" >     <bean class= " Org.codehaus.jackson.map.ObjectMapper ">     <property name=" DateFormat " >      <bean class= "Java.text.SimpleDateFormat" >      <constructor-arg index= "0"  type= "java.lang.String"  value= "Yyyy-mm-dd hh:mm:ss"/>      </bean>     </property>      </bean>     </property>     </ Bean>     <bean id= "Stringhttpmessageconverter"  class= " Org.springframework.http.converter.StringHttpMessageConverter "/>     <bean  id= "Requestmappinghandleradapter"  class= " Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter ">      <property name= "Messageconverters" >     <list>      <ref bean= "Mappingjacksonhttpmessageconverter"/>    &Nbsp;<ref bean= "Stringhttpmessageconverter"/>     </list>      </property>     </bean>          <!--  Configure JSP view  -->     <bean id= " Internalresourceviewresolver " class=" Org.springframework.web.servlet.view.InternalResourceViewResolver " >     <property name= "Viewclass"  value= " Org.springframework.web.servlet.view.JstlView "/><property name=" prefix " value="/web-inf/jsp/"/ ><property name= "suffix"  value= ". jsp"/><property name= "ContentType"  value= " Text/html;charset=utf-8 "/><property name=" Order " value=" 1 "/>      </bean>         <!--  Configure Freemark View  -->     <bean id= "FreemarkerviewreSolver " class=" Org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver ">     <property name= "ContentType"  value= "Text/html;charset=utf-8"/>         <property name= "Viewclass"  value= " Org.springframework.web.servlet.view.freemarker.FreeMarkerView "/>    <property  Name= "suffix"  value= ". FTL"/>    <property name= "cache"  value= "true"/ >    <property name= "Exposesessionattributes"  value= "true"/>     <property name= "Exposerequestattributes"  value= "true"/>         <property name= "Exposespringmacrohelpers"  value= "true"/>     <!--  Use ${rc.contextpath} on the page to get contextpath -->    < Property name= "Requestcontextattribute"  value= "RC"/>    <property name= "Order"  value= "0"/>    </ Bean>        <bean id= "Freemarkconfig"  class= " Org.springframework.beans.factory.config.PropertiesFactoryBean ">    <property  Name= "Location"  value= "Classpath:freemark.properties"/>    </bean>         <bean id= "Fmxmlescape"  class= " Freemarker.template.utility.XmlEscape "/>        <bean id=" Freemarkerconfigurer " class=" Org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer ">     <property name= "Templateloaderpath"  value= "/WEB-INF/ftl/"/>     <property name= "defaultencoding"  value= "UTF-8"/>    < Property name= "Freemarkersettings"  ref= "FREEMARKCOnfig "/>    <property name=" Freemarkervariables ">     <map>    <entry key= "Xml_escape"  value-ref= "FmXmlEscape"/>     </map>    </property>    </bean>         <!--  File Upload configuration note: The ID stated here must be multipartresolver -->     <bean id= "Multipartresolver"  class= " Org.springframework.web.multipart.commons.CommonsMultipartResolver ">        <property name= "Maxuploadsize"  value= "500000"/>    </bean>         <!--  Simple exception handling  -->    < Bean id= "Exceptionresolver"  class= " Org.springframework.web.servlet.handler.SimpleMappingExceptionResolver ">    < Property name= "ExceptioNmappings ">    <props>        <!--   Mapping directory is/web-inf/jsp/error/upload_error.jsp -->    <prop key= " Org.springframework.web.multipart.MaxUploadSizeExceededException ">/error/upload_error</prop>     </props>    </property>    </bean>         <!--  Access to static resource files  --><mvc:resources  mapping= "/images/**"  location= "/images/"  cache-period= "31556926"/><mvc:resources mapping= "/js/**"  location= "/js/"  cache-period= "31556926"  /><mvc:resources mapping= "/css/**"  location= "/css/"  cache-period= "31556926"  />         <mvc:resources mapping= "/upload/**"  location= "/upload/"  cache-period= "31556926"  /> </beans>


SPRINGMVC configuring JSON, JSP, Freemark Multi-View parser configuration

Related Article

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.