1. Use code to complete the character set modification
Method (1):
html page:
function testOne() {
var url = "testOne_test.do?expr="+Hello;
location = encodeURI( url);
}
Backend java code:
String expr = new String(request.getParameter("expr").getBytes("ISO-8859-1"),"UTF-8");
method (2):
html page:
function testOne() {
var url = "testOne_test.do?expr="+Hello;
location = encodeURI(encodeURI(url));
}
Backend java code :
String expr = java.net.URLDecoder.decode(lrequest.getParameter("expr") , "UTF-8");
2. Modify the configuration parameters in tomcat
Find server.xml under tomcat
< Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" URIEncoding="GBK">
Modify to UTF-8 and other character sets as needed.工3, add Spring.jar to the web engineering, use the Spring's CharacterencodingFilter
View Plaincopy to Clipboardprint? ding & lt;/file-name & gt;
& lt; file-class & gt; ORG.SpringFramework.Web.filter.CharacterenCodingFilter & LT;/Filter-Class & GT;
& LT; Init-Param & GT;
& LT; Param-Name & GT; Encoding & lt;/param-name & gt;
& lt; param-value & gt; utf-8 & lt;/param- value>
;/*
The transcoding part in
org.springframework.web.filter.CharacterEncodingFilter:
view plaincopy to clipboardprint?
protected void doFilterInternal(
ttpServletRequest 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);
}