`
骷髅蚂蚁
  • 浏览: 3321 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

springMVC,jQuery ajax传值的中文乱码处理

阅读更多

1.前台往后台传值

  jQuery的get()方法未对中文进行处理,需要自己在后台添加request编码设置;

  post()方法已做过处理,可以直接用,不会出现乱码问题

2.ajax的返回值

   这里针对springMVC中用jQuery的ajax方法时,返回值的中文处理

   @ResponseBody注解把返回值直接写到HTTP response body里,spring注解的默认编码是iso-8859-1,l因为工程编码和页面都是utf-8,所以乱码

在springmvc的配置文件(<servlet>-servlet.xml)中加入以下配置,可以解决乱码问题

<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/html;charset=UTF-8</value>   
                      </list>   
               </property>   
           </bean>   
        </list>   
   </property>  
</bean>  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics