SpringMVC garbled processing and SpringMVC garbled Processing

Source: Internet
Author: User

SpringMVC garbled processing and SpringMVC garbled Processing

Recently, the Spring MVC configuration file was modified because of the modification of Spring transactions. However, it was found that garbled characters were generated when AJAX was used to obtain background data. The final result is that a label is added to the SpringMVC configuration file:

<Mvc: annotation-driven/>:

<Bean class = "org. springframework. web. servlet. mvc. annotation. AnnotationMethodHandlerAdapter">
<Property name = "messageConverters">
<List>
<Bean class = "org. springframework. http. converter. StringHttpMessageConverter">
<Property name = "supportedMediaTypes">
<List>
<Value> text/plain; charset = UTF-8 </value>
</List>
</Property>
</Bean>
</List>
</Property>
</Bean>

If the <mvc: annotation-driven/> label is added, the configuration will be invalid. Due to the worry, I did not contact the source code. I directly asked du Niang. Some netizens said that adding such code can solve the problem:

<Mvc: annotation-driven>
<Mvc: message-converters>
<Bean class = "org. springframework. http. converter. StringHttpMessageConverter">
<Property name = "supportedMediaTypes">
<List>
<Value> application/json; charset = UTF-8 </value>
</List>
</Property>
</Bean>
</Mvc: message-converters>
</Mvc: annotation-driven>

In this case, the editor reports an error, indicating that the annotaion-driver tag cannot contain child elements. I went there, but I was confused by some netizens. Later I found that the XSD file version was lower, so I switched to version 3.2 to solve the problem. Modify the XSD import code, for example:

<? 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: p = "http://www.springframework.org/schema/p"
Xmlns: context = "http://www.springframework.org/schema/context"
Xmlns: aop = "The http://www.springframework.org/schema/aop" xmlns: tx = "The http://www.springframework.org/schema/tx"
Xmlns: util = "http://www.springframework.org/schema/util"
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/tx
Http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
Http://www.springframework.org/schema/aop
Http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
Http://www.springframework.org/schema/util
Http://www.springframework.org/schema/util/spring-util-3.2.xsd
Http://www.springframework.org/schema/mvc
Http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd>

If you are another version, you can also change to another version, address in: http://www.springframework.org/schema/mvc/

Therefore, the solution to each type of problem is limited by its environment and has no technical content. Remember to help other users.

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.