当前位置:网站首页>jsp页面编码
jsp页面编码
2022-04-23 07:34:00 【beinlife】
规律:
可行:utf-8编码--->gbk解码-->gbk编码-->utf解码
可行:utf-8编码--->iso8859-1解码-->iso8859-1编码-->utf解码
可行:gbk编码--->iso8859-1解码-->iso8859-1编码-->gbk解码
在JSP页面获取表单的值时会出现乱码,有两种解决方法:
一种是在调用getParameter之前通过request.setCharacterEncoding设置字符编码,
另一种是调用new String(str.getBytes("iso8859-1"), "UTF-8")编码后解码
*/
String s = "你好";
// 编码----------------------------------------
byte[] utf = s.getBytes("utf-8");
byte[] gbk = s.getBytes("gbk");
System.out.println("---------------------");
System.out.println("gbk码用utf解码再编码:" + new String((new String(gbk, "utf-8").getBytes("utf-8")),"gbk"));
System.out.println("gbk码用iso8859-1解码再编码:" + new String((new String(gbk, "iso8859-1").getBytes("iso8859-1")),"gbk"));
System.out.println("utf码用gbk解码再编码:" + new String((new String(utf ,"gbk").getBytes("gbk")),"utf-8"));
System.out.println("utf码用iso8859-1解码再编码:" + new String((new String(utf, "iso8859-1").getBytes("iso8859-1")),"utf-8"));
System.out.println("---------------------");
System.out.println("iso8859-1编码utf解码:" + new String(s.getBytes("iso8859-1"),"utf-8"));
System.out.println("iso8859-1编码gbk解码:" + new String(s.getBytes("iso8859-1"),"gbk"));
输出结果:
---------------------
gbk码用utf解码再编码:锟斤拷锟�
gbk码用iso8859-1解码再编码:你好
utf码用gbk解码再编码:你好
utf码用iso8859-1解码再编码:你好
---------------------
iso8859-1编码utf解码:??
iso8859-1编码gbk解码:??
版权声明
本文为[beinlife]所创,转载请带上原文链接,感谢
https://blog.csdn.net/beinlife/article/details/52774907
边栏推荐
- Transformer-XL: Attentive Language ModelsBeyond a Fixed-Length Context 论文总结
- An idea plug-in that doesn't work, but can install X
- Interesting JS code
- ELK生产实践
- LeetCode简单题之重新排列日志文件
- 常用正则表达式
- LeetCode中等题之旋转函数
- There are some problems when using numeric type to query string type fields in MySQL
- Qt读写XML文件
- LeetCode15. Sum of three
猜你喜欢

A simple theme of Typecho with beautiful appearance_ Scarfskin source code download

MySQL数据库中delete、truncate、drop原理详解

输入/输出系统

Discussion on ES6 tail tune optimization

Listed on the Shenzhen Stock Exchange: the market value is 5.2 billion yuan. Lu is the East and his daughter is American

监控智能回放是什么,如何使用智能回放查询录像

一键清理项目下pycharm和Jupyter缓存文件

Goland 调试go使用-大白记录

Rotation function of leetcode medium problem

Positioning of high precision welding manipulator
随机推荐
Briefly describe the hierarchical strategy of memory
常用正则表达式
ansible自動化運維詳解(一)ansible的安裝部署、參數使用、清單管理、配置文件參數及用戶級ansible操作環境構建
情境领导者-第七章、解决绩效问题
数据的删除和修改操作(mysql)
微信小程序 catchtap=“toDetail“ 事件问题
作文以记之 ~ 二叉树的后序遍历
編譯原理題-帶答案
线程的调度(优先级)
MySQL数据库中delete、truncate、drop原理详解
QT reads all files under the path or files of the specified type (including recursion, judging whether it is empty and creating the path)
JS common array methods
华硕笔记本电脑重装系统后不能读取usb,不能上网
分布式消息中间件框架选型-数字化架构设计(7)
mysql查询字符串类型的字段使用数字类型查询时问题
CGM优化血糖监测管理——移宇科技亮相四川省国际医学交流促进会
青苹果影视系统源码 影视聚合 影视导航 影视点播网站源码
数论求a^b(a,b为1e12级别)的因子之和
AQS & ReentrantLock 实现原理
The third divisor of leetcode simple question