Solve Spring3.0 MVC @ResponseBody Ajax return Chinese garbled __ajax

Source: Internet
Author: User
Tags comments

It is important to note the related configuration items in the Spring-mvc.xml (Spring controller configuration file)

 <!--scan only @controller---<context:component-scan base-package= " Cn.com.sunnyrock.vimes.portal "use-default-filters=" true "> <context:include-filter type=" Annotation " expression= "Org.springframework.stereotype.Controller"/> </context:component-scan> <!--encoding conversion, Its tacit view iso-8859-1--> <bean class= " Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter "> <property name=" Cacheseconds "value=" 0 "/> <property name=" messageconverters "> <list> <bean CL "Org.springframework.http.converter.StringHttpMessageConverter" > <property name = "Supportedm Ediatypes "> <list> <value>text/html;charset=utf-8</val ue> </list> </property> </bean> </l Ist> </property> </bean> 
	<!--annotation automatic injection, this configuration is important--
	<bean class= " Org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping "/>
        <!--must remove this configuration item <mvc:annotation-driven/>--

The method in the controller

	@RequestMapping (value = "/feedback", method = requestmethod.post) public
	@ResponseBody
	String Feedback ( HttpServletRequest request, HttpServletResponse response, Feedbackmodel feedback) throws exception{
		//todo
		Return "Thank you very much for your valuable comments or suggestions to us";
	}

Ajax calls in JSPs (Jquery.form.js This plugin is used here)

	var feedbackadviceform = "#feedbackAdviceForm";	
	$ (Feedbackadviceform). Submit (function () {
		if ($.trim ($ ("#advice", Feedbackadviceform). val ()) = = "") {
			alert ( "Please input your valuable comments or suggestions." ");
			$ ("#advice", Feedbackadviceform). focus ();
			return false;
		}
		$ (this). Ajaxsubmit ({
			success:function (msg) {
				alert (msg);
			},
			error:function (context, XHR) {
				alert (context.responsetext);});
	});
<form id= "Feedbackadviceform" name= "Feedbackadviceform" action= "<%=rootpath%>/member/feedback.html" Method= "POST" onsubmit= "return false;" >
	<p>
		<label for= "Advice" > Please enter your valuable comments or suggestions </label><br>
		<textarea id= " Advice "name=" advice "rows=" 3 "cols=" style= "width:200px; height:120px;	" ></textarea>
	</p>
	<p>
		<input type= "Submit" value= "Submission" >
	</p>
</form>


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.