1、使用代码完成字符集修改
方法(一):
html页面:
function testone() {
var url = "testone_test.do?expr="+你好;
location = encodeuri(url);
}
后台java代码:
string expr = new string(request.getparameter("expr").getbytes("iso-8859-1"),"utf-8");
方法(二):
html页面:
function testone() {
var url = "testone_test.do?expr="+你好;
location = encodeuri(encodeuri(url));
}
后台java代码:
string expr = java.net.urldecoder.decode(lrequest.getparameter("expr") , "utf-8");
2、修改tomcat中的配置参数
在tomcat下面找到server.xml
根据需要修改为utf-8等字符集。
3、在web工程中添加spring.jar,使用spring的characterencodingfilter
view plaincopy to clipboardprint?
org.springframework.web.filter.characterencodingfilter 中的转码部分:
view plaincopy to clipboardprint?
protected void dofilterinternal(
httpservletrequest request, httpservletresponse response, filterchain filterchain)
throws servletexception, ioexception {
if (this.encoding != null && (this.forceencoding || request.getcharacterencoding() == null)) {
request.setcharacterencoding(this.encoding);
if (this.forceencoding && responsesetcharacterencodingavailable) {
response.setcharacterencoding(this.encoding);
}
}
filterchain.dofilter(request, response);
}
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号