jsp linux乱码的解决办法:1、在ROOT用户下修改“LANG="zh_CN.GB2312"”;2、在处理包含汉字字符串时指定gb2312或者GB2312编码即可。

本文操作环境:linux5.9.8系统、Dell G3电脑。
如何解决jsp linux 乱码问题?
Linux下的JSP乱码解决方法
我在JSP中用的是gb2312编码
而LINUX系统默认的是UTF-8
所以导致在LINUX下运行的网站,获取数据库中的中文全是乱码,具体解决:
1.在ROOT用户下
将原来的:
1 2 3 | LANG= "zh_CN.UTF-8"
SUPPORTED= "zh_CN.UTF-8:zh_CN:zh"
SYSFONT= "latarcyrheb-sun16"
|
登录后复制
改为
1 2 3 4 5 6 7 8 9 10 | # vi /etc/sysconfig/i18n 修改该文件的内容 # 表示被注释了
#LANG= "zh_CN.UTF-8"
#SUPPORTED= "zh_CN.UTF-8:zh_CN:zh"
#SYSFONT= "latarcyrheb-sun16"
LANG= "zh_CN.GB2312"
LANGUAGE= "zh_CN.GB2312:zh_CN"
SUPPORTED= "zh_CN.GB2312:zh_CN:zh_CN.UTF-8"
SYSFONT= "lat0-sun16"
SYSFONTACM= "8859-15"
|
登录后复制
2.处理包含汉字字符的字符串时要指定gb2312或者GB2312编码
1 2 3 4 5 6 7 8 9 | 如: String caption = new String(caption.getBytes( "iso-8859-1" ), "gb2312" );
String templateContent = "" ;
FileInputStream fileinputstream = new FileInputStream(filePath);
int lenght = fileinputstream.available();
byte bytes[] = new byte[lenght];
fileinputstream.read(bytes);
fileinputstream.close();
templateContent = new String(bytes, "GB2312" );
|
登录后复制
推荐学习:《linux视频教程》
以上是如何解决jsp linux 乱码问题的详细内容。更多信息请关注PHP中文网其他相关文章!