1、使用程式碼完成字元集修改
方法(一):
html頁面:
function testOne() {
var url = url);
}
後台java程式碼:
String expr = new String(request.getParameter("expr").getBytes("ISO-8859-1"),"UTF-8")。 (二):
html頁:
function testOne() {
var url = "testOne_test.do?expr="+你好; lo :
String expr = java.net.URLDecoder.decode(lrequest.getParameter("expr") , "UTF-8");
2、修改tomcat中的設定參數
在tomcatserver.xml port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" URIEncoding="GBK">
根據需要修改為UTF-8等字元集。
3、在web工程中加入spring.jar,使用spring的CharacterEncodingFilter
view plaincopy to clipboardprint?
org.springframework .web.filter.CharacterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter 中的轉碼部分:
view plaincopy to clipboardprint?
protected vSerttFilterInter?
¢ ponse response, FilterChain filterChain)
throws ServletException, IOException {
this.encoding != null && (this.forceEncoding || request.getCharacterEncoding() == null)) {
request.setCharacterEncoding(this.encoding);
response.setCharacterEncoding(this .encoding);
}
}
filterChain.doFilter(request, response); filterChain.doFilter(request, response);