没有合适的资源?快使用搜索试试~ 我知道了~
我总结的中文处理问题.txt
需积分: 9 1 下载量 40 浏览量
2008-10-02
19:11:40
上传
评论
收藏 1KB TXT 举报
温馨提示
试读
2页
<%! public static String change(String str) { String temp = ""; try { temp = new String(str.getBytes("ISO-8859-1"), "GBK").trim(); } catch (Exception e) { e.printStackTrace(); } return temp; }%>
资源推荐
资源详情
资源评论
指令 :<@page contentType ="text/html; charset=utf-8" %> 这个是设置浏
改成 gbk 或者 gb2312l
览器默认的字符编码,可以解决没有 “请求内容为中文”的页面,可以打印输出中文显示的页面.
但是如果: request.getParamter("name"); //传过来的是中文.
GBK >GB2312 ;
GBK 是中文编码、GB2312 是简体中文编码.
若要解决问题:
方法一、 String name = new String (request.getParameter("name").getBytes("ISO-8859-1"));
方法二、设置统一的字符编码:
public void setCharacterEncoding(String env) throws Exception {}
设置统一的请求编码:
request.setCharacterEncoding("GBK");
String name = request.getParameter("name"); //照样可以过的中文字符
注意: 在j2ee中乱码的问题是最重大的问题---作到国际通用
方法三、处理get请求的中文问题.更加特殊
可以写个全局的方法
<%!
public static String change(String str) {
String temp = "";
try {
temp = new String(str.getBytes("ISO-8859-1"), "GBK").trim();
} catch (Exception e) {
e.printStackTrace();
}
return temp;
}%>
String name = change(request.getParameter("name"));
改成 gbk 或者 gb2312l
览器默认的字符编码,可以解决没有 “请求内容为中文”的页面,可以打印输出中文显示的页面.
但是如果: request.getParamter("name"); //传过来的是中文.
GBK >GB2312 ;
GBK 是中文编码、GB2312 是简体中文编码.
若要解决问题:
方法一、 String name = new String (request.getParameter("name").getBytes("ISO-8859-1"));
方法二、设置统一的字符编码:
public void setCharacterEncoding(String env) throws Exception {}
设置统一的请求编码:
request.setCharacterEncoding("GBK");
String name = request.getParameter("name"); //照样可以过的中文字符
注意: 在j2ee中乱码的问题是最重大的问题---作到国际通用
方法三、处理get请求的中文问题.更加特殊
可以写个全局的方法
<%!
public static String change(String str) {
String temp = "";
try {
temp = new String(str.getBytes("ISO-8859-1"), "GBK").trim();
} catch (Exception e) {
e.printStackTrace();
}
return temp;
}%>
String name = change(request.getParameter("name"));
资源评论
ThankyouYakSje
- 粉丝: 4
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功