Web项目,异步获取,数据展示乱码的问题笔记
来源:互联网 发布:淘宝商城weimeixiaowu 编辑:程序博客网 时间:2024/05/01 03:11
参与的一个后台管理系统的开发,涉及到SpringMVC,Maven,Gson,Velocity等相关技术
问题:Ajax请求,转到服务器,进行逻辑判断后,传回结果,显示????
检查:web.xml中配置了包含字符过滤器,velocity头信息包含UTF-8字符集设置,velocity配置文件表明字符集设置UTF-8,spring配置文件中对于velocity页面的部分配置。
<filter> <filter-name>CharacterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter><filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>
<meta charset="utf-8">
input.encoding=UTF-8output.encoding=UTF-8
<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver"> <property name="suffix" value=".vm" /> <property name="exposeRequestAttributes" value="true"/> <property name="exposeSessionAttributes" value="true" /> <property name="contentType" value="text/html;charset=UTF-8" /><!-- 页面使用工具类配置 --><property name="toolboxConfigLocation" value="/WEB-INF/toolbox.xml"/></bean>依旧存在该问题,
解决方案如下:在spring中增加配置
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="urlDecode" value="true"/> <property name="messageConverters"> <list> <bean class=" org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/> <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/> <bean class="org.springframework.http.converter.StringHttpMessageConverter"/> <bean class="org.springframework.http.converter.FormHttpMessageConverter"/> <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/> </list> </property> </bean>
初步判断问题原因在
org.springframework.http.converter.StringHttpMessageConverter中的默认字符集是ISO-8859-1,造成的字符转换问题,问题虽然解决,但还有很多东西不是很理解,继续加油吧
阅读全文
0 0
- Web项目,异步获取,数据展示乱码的问题笔记
- js异步获取数据的问题
- web项目乱码问题
- web项目乱码问题
- 解决Web项目乱码的问题
- Tomcat的web项目乱码问题
- 关于web项目的乱码问题总结
- Java Web后台从request里面获取的数据是乱码问题
- web 项目从数据库读取数据时出现乱码的问题的解决
- java项目 java web项目数据库乱码问题的解决办法
- web项目中文乱码问题
- web项目中文乱码问题
- Ajax异步交互解决数据乱码问题
- Velocity笔记--使用Velocity获取动态Web项目名的问题
- Vue.js实现的异步获取数据并以表格形式展示内容,实现基本的增删改查操作
- 解决web项目开发中常见的中文乱码问题
- 基于J2EE的web项目中的乱码问题
- web项目中的乱码问题的原因及解决办法
- js贪吃蛇
- svn提示 update Error converting entry in directory
- 来听大师讲设计(上)
- 图层CALayer
- LaTeX学习笔记(一)—Hello World!
- Web项目,异步获取,数据展示乱码的问题笔记
- jvm 闲聊
- 侧拉和第三方登陆,日夜
- elasticsearch介绍集群,模拟横向扩展节点、节点宕机、改变分片
- uboot分析之Makefile(一)
- Class类文件的结构
- ss-libev 源码解析local篇(5):ss-local之remote_send_cb
- vb.net中usercontrol向外抛出事件和属性
- LinuxMint 下安装 tomcat8