解决Spring3.0 MVC @ResponseBody Ajax返回中文乱码

主要是要注意spring-mvc.xml(spring 的 controller配置文件)中的相关配置项

	
	
		
	
	
	
        
       	
			 
	             
	                
	                      
	                          text/html;charset=UTF-8
	                     
	                
	             
         	
		
    	
	
	
        

Controller中的方法

	@RequestMapping(value = "/feedback", method = RequestMethod.POST)
	public @ResponseBody
	String feedback(HttpServletRequest request, HttpServletResponse response, FeedbackModel feedback) throws Exception{
		//TODO
		return "非常感谢您对我们提出的宝贵意见或建议";
	}

JSP中的Ajax调用(这里使用了jquery.form.js这个plugin)

	var feedbackAdviceForm = "#feedbackAdviceForm";	
	$(feedbackAdviceForm).submit(function() {
		if($.trim($("#advice",feedbackAdviceForm).val())==""){
			alert("请输入您的宝贵意见或建议!");
			$("#advice",feedbackAdviceForm).focus();
			return false;
		}
		$(this).ajaxSubmit({
			success: function(msg) {
				alert(msg);
			},
			error: function(context, xhr) {
				alert(context.responseText);
			}
		});
	});


 



你可能感兴趣的:(Spring)