首页 技术 正文
技术 2022年11月10日
0 收藏 867 点赞 5,176 浏览 1460 个字

先准备一个网页

<html>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>测试编码</title>
<body>
<form id="form1" name="form1" method="post" action="http://localhost:8080/TestServer/Receive">
<label>
<input type="text" name="name" />
</label>
<label>
<input type="submit" name="SBbt" value="提交" />
</label>
</form>
</body>
</html>

网页提交中文到WEB容器的经历了些什么过程….

输入中文字,名字   “何锦彬”  进行提交

提交到servelt , 用servelt输出收到的内容

protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
InputStream input = request.getInputStream();
BufferedInputStream inputBf = new BufferedInputStream(input);
byte[] buf = new byte[1024];
int length = inputBf.read(buf);
byte[] receviveData = new byte[length];
System.arraycopy(buf, 0, receviveData, 0, length); System.out.println("收到:" + new String(receviveData));// System.out.println(request.getParameter("name"));
}

输出如下:

收到:name=%BA%CE%BD%F5%B1%F2&SBbt=%CC%E1%BD%BB

尝试把”何锦彬” 按GBK转成 16进制输出

ffffffba ffffffce ffffffbd fffffff5 ffffffb1 fffffff2 

忽略前面的’f’, 会发现,servelt接受到的内容就是: 中文经过GBK编码转码后, 用16进制标识, 并在前面加上”%”以作区分

继续修改修改网页的meta信息,把”GBK” 换成”utf-8″

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

输出如下:

收到:name=%E4%BD%95%E9%94%A6%E5%BD%AC&SBbt=%E6%8F%90%E4%BA%A4

明显 name 后面是9个字符,是用UTF-8转码后16进制表示了字节后再加了’%’ 组成

整个过程如下

1, 把中文根据mate 里的字符编码转换成字节

2, 把字节加上百分号并用16进制表示

(1,2部相当于java.net.URLEncoder.encode(content,”utf-8″))

3. 进行传输

4, WEB容器进行解码,相当于调用

TOMCAT中相关代码

org.apache.tomcat.lite.http.HttpRequest    672行

 try {
parameters.add(urlDecode(tmpName, enc),
urlDecode(tmpValue, enc));
} catch (IOException e) {
// ignored
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,117
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,589
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,435
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,206
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,842
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,927