Coding analysis __get&post in Java development

Source: Internet
Author: User

Get method Submit Parameter Analysis

code.jsp

1 <%@ Page Language="Java"ContentType="text/html; Charset=utf-8"2 pageencoding="UTF-8"%>3 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd ">4 <HTML>5 <Head>6 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8">7 <title>Insert Title here</title>8 </Head>9 <Body>Ten     <formAction= "${pagecontext.request.contextpath}/doget"Method= "Get"> One         <inputtype= "text"name= "Name"> A         <inputtype= "Submit"value= "Submit"> -     </form> - </Body> the </HTML>

Dogetservlet

1 <connector connectiontimeout= "20000" port= "in" protocol= "http/1.1" redirectport= "8443" >

1     protected voiddoget (httpservletrequest request, httpservletresponse response)2             throwsservletexception, IOException {3         //the composition of the URL4         //Domain name: port/contextpath/servletpath/pathinfo?querystring5         6         //1. No processing of the obtained request parameters, the result is "iso-8859-1" after decoding the parameters7String name1 = request.getparameter ("name");8System.out.println (NAME1);//name1 =??????? 9         Ten         //2. First encode with "iso-8859-1" and then decode with "UTF-8 " OneString name2 = Urlencoder.encode (Request.getparameter ("name"), "Iso-8859-1"); Aname2 = Urldecoder.decode (name2, "Utf-8"); -System.out.println (name2);//name2 = Ah ah ah -          the         //3. Use the constructor of string to process the requested parameters, -         //decodes the specified byte array by using the specified charset . -         //constructs a new String.  -String Name3 = +                 NewString (Request.getparameter ("name"). GetBytes ("Iso-8859-1"), "Utf-8"); -System.out.println (Name3);//Name3 = Ah ah ah +          A}

1 <connector connectiontimeout= "20000" port= "in" protocol= "http/1.1" redirectport= "8443" URIEncoding = "UTF-8"/>

1 protected voiddoget (httpservletrequest request, httpservletresponse response)2             throwsservletexception, IOException {3         //the composition of the URL4         //Domain name: port/contextpath/servletpath/pathinfo?querystring5         6         //1. No processing of the obtained request parameters, the result is "iso-8859-1" after decoding the parameters7String name1 = request.getparameter ("name");8System.out.println (NAME1);//name1 = Ah ah ah9         Ten         //2. First encode with "iso-8859-1" and then decode with "UTF-8 " OneString name2 = Urlencoder.encode (Request.getparameter ("name"), "Iso-8859-1"); Aname2 = Urldecoder.decode (name2, "Utf-8"); -System.out.println (name2);//name2 =??? -          the         //3. Use the constructor of string to process the requested parameters, -         //decodes the specified byte array by using the specified charset . -         //constructs a new String.  -String Name3 = +                 NewString (Request.getparameter ("name"). GetBytes ("Iso-8859-1"), "Utf-8"); -System.out.println (Name3);//Name3 =??? +          A}

Post mode submit parameter analysis

code.jsp

1 <%@ Page Language="Java"ContentType="text/html; Charset=utf-8"2 pageencoding="UTF-8"%>3 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd ">4 <HTML>5 <Head>6 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8">7 <title>Insert Title here</title>8 </Head>9 <Body>Ten     <formAction= "${pagecontext.request.contextpath}/doget"Method= "POST"> One         <inputtype= "text"name= "Name"> A         <inputtype= "Submit"value= "Submit"> -     </form> - </Body> the </HTML>
 1  protected  void   DoPost (HttpServletRequest request, httpservletresponse response)  2  throws   servletexcept  Ion, IOException { 3  4  // 1. The obtained request parameter is not processed, and the result is "iso-8859-1" the decoded parameter  5  String name1 = request.getparameter ("name"     6  System.out.println (name1); // name1 =???????  7  8 } 
1 protected voidDoPost (httpservletrequest request, httpservletresponse response)2             throwsservletexception, IOException {3         4         //2. Set the request parameter to "UTF-8" and get the result "UTF-8"?? Parameters after decoding5Request.setcharacterencoding ("Utf-8");6String name2 = request.getparameter ("name");7System.out.println (name2);//name1 = Ah ah ah8}


Coding analysis __get&post in Java development

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.