惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
The Register - Security
The Register - Security
S
Securelist
Simon Willison's Weblog
Simon Willison's Weblog
T
The Exploit Database - CXSecurity.com
V
Vulnerabilities – Threatpost
NISL@THU
NISL@THU
P
Privacy & Cybersecurity Law Blog
V2EX - 技术
V2EX - 技术
O
OpenAI News
N
News and Events Feed by Topic
AI
AI
P
Proofpoint News Feed
Schneier on Security
Schneier on Security
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Cloudbric
Cloudbric
Help Net Security
Help Net Security
C
Cyber Attacks, Cyber Crime and Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Security Latest
Security Latest
Application and Cybersecurity Blog
Application and Cybersecurity Blog
L
LINUX DO - 热门话题
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
The Hacker News
The Hacker News
Hacker News - Newest:
Hacker News - Newest: "LLM"
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Google DeepMind News
Google DeepMind News
H
Hacker News: Front Page
C
Cisco Blogs
Webroot Blog
Webroot Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hacker News: Ask HN
Hacker News: Ask HN
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Last Watchdog
The Last Watchdog
PCI Perspectives
PCI Perspectives
AWS News Blog
AWS News Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Forbes - Security
Forbes - Security
I
Intezer
Project Zero
Project Zero
C
CERT Recently Published Vulnerability Notes
T
Tenable Blog
TaoSecurity Blog
TaoSecurity Blog
S
Security @ Cisco Blogs
N
News | PayPal Newsroom
H
Heimdal Security Blog
W
WeLiveSecurity

博客园 - yueue

Ext Portal如何消除横向滚动条 JavaScript中的对象动态加载技术 JavaScript使用ACTIVEX控件引起崩溃问题的解决 如何把Ext.data.store里的数据一次性用JSON传给后台(添加了后台解析部分) 解决EXT DateField 用getValue() 发送到后台,后台取null的问题 - yueue 如何使开启了分页功能的EXT Combox可以自动选中非第一页的值 ExtJs 中一个Toolbar 不够用?再来一个! - yueue 为什么ext combox 下拉框不出现自动提示,自动选中 如何做一个两列的FormPanel json-lib出现There is a cycle in the hierarchy解决办法 EXT如何把一个对象转换为JSON并将其发送到服务器 - yueue - 博客园 ExtJs如何通过JSON与后台通信 [教程]创建ADOKeycap数据库对象 认识 yueue.ADOKeycap 开源数据库组件 [教程]使用yueueData统计数据 [教程]在ADOKeycap中使用DataReader读取数据 [教程]使用ADOKeycap插入,更新,删除数据 [教程]使用AODKeycap读取数据 [教程]添加yueue.ADOKeycap数据库组件到您的项目 - yueue - 博客园
ExtJs 及 Ajax 乱码解决方案 - yueue
yueue · 2010-02-21 · via 博客园 - yueue

    在Ext的使用过程中,一不留心就出现了乱码,包括在客户端提交给服务器的数据中出现了乱码和服务器端返回给客户端的数据中出现了乱码,下面简单分析一下出现乱码的原因。

  在一次页面浏览过程中,客户端对一个URL发起浏览请求,服务端针对这次请求进行解析,而在字符编码解析方面,首先他检查该页面中的字符编码设置,即<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />,这样,在页面中显示声明了字符编码为UTF-8,服务器就会将该页面用UTF-8的编码输出,而如果页面中没有显示声明,在服务器中都有一个默认的字符编码,比如GB2312,针对没有声明的文件,他会用默认编码输出,这个时候,如果页面输出又是UTF-8,这样就会出现乱码。

  而在Ext中的提交数据的过程中,Ext框架用的是都是UTF-8编码,而且通过JSON提交的数据也是UTF-8编码,所以要求所有的文件都是UTF-8编码。

解决乱码的方法

    以下几项首先必须要在平时的编码过程中做到:

  (1) JAVA后台文件加入 response.setContentType("text/html");
  response.setCharacterEncoding("utf-8");

  (2)在文件中显示声明字符编码,<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  (3)对于提交中出现的乱码,在Ext中可以修改Request Header中Content-Type的设置,具体的方法为:Ext.lib.Ajax.defaultPostHeader += ";charset=utf-8";

最后,问题还可能出现在文件的保存格式上。就是你把代码文件保存的时候,如果开发环境默认保存的不是UTF-8格式,那么也会出现问题! 所以就要对开发环境也有一个要求。

开发环境的配置

    如果采用记事本来编写保存代码文件(.js),那这个就会出问题,主要是由于在windows系统里记事本默认的编码格式是ANSI,这样基本上和目前网页中编码的格式都不同因此就会出现编码格式不正确的问题。解决办法就是打开xx.js文件然后另存为,在保存类型处选择utf-8编码格式就可以了。 

当然,主流还是使用MyEclipse,所以说一下MyEclipse里要配置哪些地方。

  1. Preferences->General->Content Types 选中Text 编辑下面的Default encoding 为utf-8然后Update。
  2. Preferences->General->Content Types->Editors->Text Editors->Spelling 下Encoding 选 Default(UTF-8)
  3. Preferences->General->Content Types->Workspace下Text File Encoding 选 Other: UTF-8

若不是,利用web.xml中的 filter 解决.

 <filter>
  <description>no</description>
  <display-name>EncodingFilter</display-name>
  <filter-name>EncodingFilter</filter-name>
  <filter-class>
   com.hope.filters.SetCharacterEncodingFilter
  </filter-class>
  <init-param>
   <param-name>encoding</param-name>
   <param-value>utf-8</param-value>
  </init-param>
 </filter>

<globalization responseEncoding="utf-8" fileEncoding="utf-8" requestEncoding="utf-8"/>