What is the process of submitting web pages in Chinese to web containers ....

Source: Internet
Author: User

Prepare a Web page first

<meta http-equiv= "Content-type" content= "text/html; CHARSET=GBK "/><title> test code </title><body><form id=" Form1 "Name=" Form1 "method=" POST "action= "Http://localhost:8080/TestServer/Receive" >  <label>  <input type= "text" name= "name"/>  </label>  <label>  <input type= "Submit" Name= "SBBT" value= "Submit"/>  </label></ Form></body>

Input Chinese text, name "He Jinbin" to submit

Submit to Servelt, output the content received with Servelt

protected voidDoPost (httpservletrequest request, httpservletresponse response)throwsservletexception, IOException {inputstream input=Request.getinputstream (); Bufferedinputstream INPUTBF=Newbufferedinputstream (input); byte[] buf =New byte[1024]; intLength =Inputbf.read (BUF); byte[] Recevivedata =New byte[length]; System.arraycopy (BUF,0, Recevivedata, 0, length); System.out.println ("Received:" +NewString (Recevivedata));//System.out.println (Request.getparameter ("name"));}

The output is as follows:

Roger: Name=%ba%ce%bd%f5%b1%f2&sbbt=%cc%e1%bd%bb

Try to turn "He Jinbin" into a 16-input output by pressing GBK.

Ignoring the previous ' F ', you will find that the content of the Servelt is: Chinese after the GBK code transcoding, with 16 binary logo, and in front with "%" to make a distinction

Continue to modify the meta-information of the Web page and replace "GBK" with "Utf-8"

<http-equiv= "Content-type"  Content= "text/html; Charset=utf-8"  />

The output is as follows:

Roger: Name=%e4%bd%95%e9%94%a6%e5%bd%ac&sbbt=%e6%8f%90%e4%ba%a4

The obvious name is followed by 9 characters, which is a 16 binary notation after the UTF-8, and the '% ' component is added after the word.

The whole process is as follows

1. Convert Chinese to bytes according to the character encoding in mate

2, byte plus percent sign and 16 binary

(1, 2 equivalent of Java.net.URLEncoder.encode (content, "Utf-8"))

3. Carry out the transfer

4, the Web container is decoded, which is equivalent to calling

Related code in Tomcat

Org.apache.tomcat.lite.http.HttpRequest 672 Lines

Try {                Parameters.Add (UrlDecode (tmpname, enc),                        UrlDecode (tmpvalue, ENC));             Catch (IOException e) {                //  ignored            }

What is the process of submitting web pages in Chinese to web containers ....

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.