Servlet submits "get post"

Source: Internet
Author: User

Importjava.io.IOException;ImportJava.io.PrintWriter;Importjavax.servlet.ServletException;ImportJavax.servlet.http.HttpServlet;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse; Public classCharSetextendsHttpServlet {/*** Constructor of the object. */     PublicCharSet () {Super(); }    /*** Destruction of the servlet. <br>*/     Public voiddestroy () {Super. Destroy ();//Just puts "destroy" string in log//Put Your code here    }    /*** The Doget method of the servlet. <br> * * This method was called when a form have its tag value me     Thod equals to get. *      * @paramRequest * The request send by the client to the server *@paramResponse * The response send by the server to the client *@throwsservletexception * If an error occurred *@throwsIOException * If an error occurred*/     Public voiddoget (httpservletrequest request, httpservletresponse response)throwsservletexception, IOException {//String str = request.getparameter ("XH"); //String str2 = new String (Str.getbytes ("iso-8859-1"), "Utf-8"); //System.out.println (str); //System.out.println (STR2); //This is to tell the browser how to follow the code to parse//Response.setheader ("Content-type", "text/html;charset=utf-8"); // //Response.getoutputstream (). Write (Str2.getbytes ("Utf-8")); //response.getwriter (). write (STR2); //tells the servlet to parse by encoding//response.setcharacterencoding ("Utf-8");GETTJ (request, response);//Method 2    }    /*** The DoPost method of the servlet. <br> * * This method was called when a form have its tag value     Method equals to * post. *      * @paramRequest * The request send by the client to the server *@paramResponse * The response send by the server to the client *@throwsservletexception * If an error occurred *@throwsIOException * If an error occurred*/     Public voidDoPost (httpservletrequest request, httpservletresponse response)throwsservletexception, IOException {request.setcharacterencoding ("Utf-8"); String str1= Request.getparameter ("XH"); Response.setcontenttype ("Text/html;charset=utf-8");    Response.getwriter (). write (STR1); }    /*** Initialization of the servlet. <br> * *@throwsservletexception * If an error occurs*/     Public voidInit ()throwsservletexception {//Put Your code here    }     Public Static voidGETTJ (httpservletrequest request, httpservletresponse response)throwsservletexception, IOException {response.setheader ("Content-type", "Text/html;charset=utf-8"); String str1=request.getquerystring (); String str2= Java.net.URLDecoder.decode (str1, "Utf-8"); String[] Arr= Str2.split ("&");  for(String Str:arr) {string[] str3= Str.split ("="); Response.getwriter (). Write (str3[1]); }    }}
View Code

Servlet submits "get post"

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.