Summary of Chinese methods after URL

Source: Internet
Author: User
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") ;  }
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.