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