Java gbk转utf-8

发布于 2020-12-30|标签java
复制链接
本文主要介绍了Java gbk转utf-8的方法,具有一定的参考价值,下面跟着小妖一起来看下吧
1、文件转码:使用脚本gbk转utf-8的脚本文件: ```java #!/bin/bash FILE_SUFFIX="java xml html vm js" # FILE_SUFFIX="vm" file_names="" for x in $FILE_SUFFIX do file_names=`find . -name "*.$x" | xargs file -I | grep -v utf-8 | awk -F " |:" '{print $1}'` for file_name in $file_names do # echo $file_name iconv -f cp936 -t UTF-8 $file_name >$file_name".new" && mv -f "$file_name.new" "$file_name" done echo "$x ok" done find . -name "*.xml" | xargs sed -i "" "//s/GBK/UTF-8/g" find . -name "pom.xml" | xargs sed -i "" "//s/GB2312/UTF-8/g" find . -name "pom.xml" | xargs sed -i "" "/project.build.sourceEncoding/s/GBK/UTF-8/g" find . -name "pom.xml" | xargs sed -i "" "/project.reporting.outputEncoding/s/GBK/UTF-8/g" find . -name "pom.xml" | xargs sed -i "" "s/pop-vender-common-pageframe/pop-vender-common-pageframe-utf8/g" echo "pom.xml is ok!" find . -name "*.properties" | xargs sed -i "" "/input.encoding/s/GBK/UTF-8/g" find . -name "*.properties" | xargs sed -i "" "/output.encoding/s/GBK/UTF-8/g" echo "velocity properties is OK!" find . -name "strut*.xml" | xargs sed -i "" '/struts.i18n.encoding/s/GBK/UTF-8/g' echo "struts xml is ok!" find . -name "*.vm" | xargs sed -i "" "s/\/common\/js\/jdmsg\/jd-msg.js/\/common\/js\/jdmsg\/jd-msg-utf8.js/g" find . -name "*.vm" | xargs sed -i "" "/\/ui.datepicker.js/s/2、文件转码后,本地环境改成utf-8环境,可能会有部分乱码文件,手动修复3、含有中文js引用增加charset="gbk"   如依赖:static.360buying.com、shop.jd.com4、打包编译编码:替换成UTF-85、xml设置格式:以前可能为gbk或gb2312,改成utf-86、web.xml转成UTF-8,请求拦截器字符编码   如使用spring配置 ```xml charsetFilter org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 forceEncoding true ``` 7、代码GBK使用  主要是代码里面写死GBK方式  如string.getBytes("GBK")替换 8、jdurl配置编码增加避税分页中含有中文乱码如:jdurl的编码设置: ```java ``` 大概是这8条重点在后面:这时你会发现,页面的get请求请求服务器时还是会出现乱码,别慌,那是因为tomcat的编码你还没有设置. 利用request.setCharacterEncoding("UTF-8");来设置Tomcat接收请求的编码格式,只对POST方式提交的数据有效,对GET方式提交的数据无效!要设置GET的编码,可以修改server.xml文件中,相应的端口的Connector的属性:URIEncoding="UTF-8",这样,GET方式提交的数据才会被正确解码。 ```java ``` 这样就ok了!!!原文地址: http://www.cnblogs.com/xiaoming0601/p/6369901.html
冀ICP备17029012号-4 | 版权所有©鲍亚龙 |免责声明  | GIF图库  | NUXT版