SPRINGMVC return JSON and JSP page XML configuration

Source: Internet
Author: User

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

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.