Test environment:
Server tomcat5.0,
Development Tools Myeclipse6.5,
The filter has been configured to encode utf-8.
Method One: Modify the Tomcat configuration
Assume that the Web service uses 8080 as the port, modify the/conf/server.xml, add red this segment
<connector port= "8080" maxthreads= "All" minsparethreads= "" maxsparethreads= "" enablelookups= "" false " Redirectport= "8443" acceptcount= "debug=" 0 "connectiontimeout=" 20000 "disableuploadtimeout=" true "URIEncoding=" Utf-8 "/>
Pass Value Code
JSP code
var url= "/yourwebapp/test.do?field1= Test Example"; window.open (URL, "", "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,top=192,left=256, Width=650,height=350 ");
Get Value Code
Java code
String field1=request.getparameter ("field1"); if (null = = field1) { field1=request.getparameter ("field1"). Trim ();
Method two: Using Java.net.URLEncoder and Java.net.URLDecoder
Assuming that method one is not used, the second method can be used.
Pass Value Code
JSP code
var url= "/yourwebapp/test.do?field1=<%=java.net.urlencoder.encode (" test Example "," UTF-8 ")%>"; window.open (URL, "", "toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,top=192,left=256, Width=650,height=350 ");
Get Value Code
Java code
String field1=request.getparameter ("field1"); if (null = = field1) { field1=request.getparameter ("field1"). Trim (); Field1=java.net.urldecoder.decode (field1, "UTF-8"); Tomcat uses iso-8859-1 for urlencoding by default and needs to convert it to the encoding we need field1=new String (field1.getbytes ("iso-8859-1"), "UTF-8") ; }