SPRINGMVC return JSON and JSP page XML configuration
Code Listing 1:
<!--dispatcherservlet Context:defines this servlet ' s request-processing infrastructure -- <!--enables the Spring MVC @Controller programming model -- <annotation-driven /> <!--Handles HTTP GET requests for/resources/** by efficiently serving up static resources in the ${webapp Root}/resources Directory -- <resources Mapping="/resources/**" location ="/resources/" /> <!--resolves views selected for rendering by @Controllers to. JSP Resources in The/web-inf/views Director Y -- <beans:beanclass=" Org.springframework.web.servlet.view.InternalResourceViewResolver "> <beans:property name="prefix" value="/web-inf/views/" /> <beans:property name="suffix" value=". jsp" /> </Beans:bean> <context:component-scan base-package="Com.sun4j.app" /> <!--avoid IE in AJAX request, return JSON appears download- <!--return JSON method two need to import jackson-annotations.jar,jackson-core.jar,jackson-databind.jar--> <beans:bean class=" Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping " /> <beans:bean class=" Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter "> <beans:property name="Messageconverters"> <beans:list> <beans:bean class=" Org.springframework.http.converter.StringHttpMessageConverter "> <beans:property name="Supportedmediatypes"> <beans:list> <beans:value>text/html; Charset=utf-8</beans:value> <beans:value>Application/json;charset=utf-8</beans:value> </beans:list> </beans:property> </Beans:bean> <beans:bean class=" Org.springframework.http.converter.json.MappingJackson2HttpMessageConverter "> <beans:property name="Supportedmediatypes"> <beans:list> <beans:value>text/html; Charset=utf-8</beans:value> <beans:value>Application/json;charset=utf-8</beans:value> </beans:list> </beans:property> </Beans:bean> </beans:list> </beans:property> </Beans:bean>
Code Listing 2:
<!--start Springmvc annotation driver <mvc:annotation-driven/> <!--return JSON method one needs to import Fastjson.jar package -- <mvc:annotation-driven> <mvc:message-converters register-defaults="false"> <!--avoid IE when performing Ajax, return JSON appears download file- - <bean id= "fastjsonhttpmessageconverter" class=" Com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter "> < property name="Supportedmediatypes"> <list> <!--Here the order can not be reversed, must first write text/html, or IE under the download prompt <value>Text/html;charset=utf-8</value> <value>Application/json;charset=utf-8</value> </list> </Property > </Bean> </mvc:message-converters> </mvc:annotation-driven> <!--return JSON method two need to import jackson-annotations.jar,jackson-core.jar,jackson-databind.jar--> <Bean class=" Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping "/> <Bean class=" Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter "> < property name="Messageconverters"> <list> <Bean class="Org.springframework.http.converter.StringHttpMessageConverter" > < property name="Supportedmediatypes"> <list> <value>text/html; Charset=utf-8</value> <value>Application/json;charset=utf-8</value> </list> </Property > </Bean> <Bean class=" Org.springframework.http.converter.json.MappingJackson2HttpMessageConverter "> < property name="Supportedmediatypes"> <list> <value>text/html; Charset=utf-8</value> <value>Application/json;charset=utf-8</value> </list> </Property > </Bean> </list> </Property > </Bean>
<!--configuration View Resolver -- <Bean class="Org.springframework.web.servlet.view.InternalResourceViewResolver" > < property name="prefix" value="/web-inf/jsp/"/> < property name="suffix" value=". jsp"/><!--can be empty, easy to implement their own based on the extension to select the View Interpretation class logic-- < property name= "viewclass" value=" Org.springframework.web.servlet.view.JstlView " /> </Bean>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
SPRINGMVC return JSON and JSP page XML configuration