Servlet Job 2-output product information submitted by the form to the page

Source: Internet
Author: User

1. Form page shangpin.html

1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "UTF-8">5 <title>Product Information</title>6 </Head>7 <Body>8 9Product Information<BR>Ten  One <formAction= "SHP"Method= "POST"> A  -Product Name:<inputtype= "text"name= "Name" > - <BR> theProduct Category:<inputtype= "Radio"name= "Kind"value= "Food"checked>Food - <inputtype= "Radio"name= "Kind"value= "office Supplies">Office Supplies - <inputtype= "Radio"name= "Kind"value= "Clothing">Apparel - <BR> + Product Description: - <BR> + <textarearows= "Ten"cols= " the"name= "Intr"></textarea> A <BR> at <inputtype= "Submit"value= "Submit"> -  - </form> -  - </Body> - </HTML>

2. Receive processing Servlet:shp.java

1  PackageCom.hanqi;2 3 Importjava.io.IOException;4 Importjavax.servlet.ServletException;5 ImportJavax.servlet.http.HttpServlet;6 Importjavax.servlet.http.HttpServletRequest;7 ImportJavax.servlet.http.HttpServletResponse;8 9 /**Ten * Servlet Implementation class SHP One  */ A  Public classShpextendsHttpServlet { -     Private Static Final LongSerialversionuid = 1L; -         the     /** -      * @seeHttpservlet#httpservlet () -      */ -      PublicShp () { +         Super(); -         //TODO auto-generated Constructor stub +     } A  at     /** -      * @seeHttpservlet#doget (httpservletrequest request, httpservletresponse response) -      */ -     protected voidDoget (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException { -         //TODO auto-generated Method Stub -         //specifying a character set inResponse.setcharacterencoding ("GBK"); -Request.setcharacterencoding ("Utf-8"); to         //Get form submission Information +String name = Request.getparameter ("name"); -String kind = request.getparameter ("Kind"); theString intr = Request.getparameter ("Intr"); *          $ //        //Request Character Set conversionPanax Notoginseng //string zname = new String (Name.getbytes ("iso-8859-1"), "Utf-8"); - //string zkind = new String (Kind.getbytes ("iso-8859-1"), "Utf-8"); the //string zintr = new String (Intr.getbytes ("iso-8859-1"), "Utf-8"); + //         AResponse.getwriter (). Append ("Product Name:" + name + "; Product Category: "+ Kind +"; Product Description: "+intr); the          +         //response.getwriter (). Append ("Served at:"). Append (Request.getcontextpath ()); -     } $  $     /** -      * @seeHttpservlet#dopost (httpservletrequest request, httpservletresponse response) -      */ the     protected voidDoPost (HttpServletRequest request, httpservletresponse response)throwsservletexception, IOException { -         //TODO auto-generated Method StubWuyi doget (request, response); the //response.setcharacterencoding ("GBK"); - //request.setcharacterencoding ("Utf-8"); Wu //        //Get form submission Information - //String name = Request.getparameter ("name"); About //String kind = request.getparameter ("kind"); $ //String intr = Request.getparameter ("Intr"); - //         - //response.getwriter (). Append ("Product Name:" + name + "; Product Category: "+ Kind +"; Product Description: "+ intr); -  A     } +  the}

Servlet Job 2-output product information submitted by the form to the page

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.