<!DOCTYPE HTML><HTML><Head><MetaCharSet= "UTF-8"><title>Form</title></Head><Body><formAction= "Tijiao"Method= "POST">Add product information:<BR><BR>Product Name:<inputtype= "text"ID= "Name"name= "Name"><BR><BR>Commodity Manufacturers:<inputtype= "text"ID= "Changs"name= "Changs"><BR><BR>Service Life:<inputtype= "text"ID= "Shoum"name= "Shoum"><BR><BR>Factory Address:<inputtype= "text"ID= "Dizhi"name= "Dizhi"><BR><BR><inputtype= "Submit"value= "Submit"></form></Body></HTML>
index.html
Package Com.hanqi;import Java.io.ioexception;import Javax.servlet.servletconfig;import Javax.servlet.servletcontext;import Javax.servlet.servletexception;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import javax.servlet.http.httpsession;/** * Servlet Implementation class Tijiao */public class Tijiao extends HttpServlet {PR Ivate static final Long serialversionuid = 1L; String str = ""; /** * @see httpservlet#httpservlet () */public Tijiao () {super (); TODO auto-generated Constructor stub}/** * @see httpservlet#doget (httpservletrequest request, Httpservletre Sponse response) */public void init (ServletConfig config) throws servletexception {str = confi G.getinitparameter ("type"); } protected void Doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException { if (Str.equals ("1")) {response.setcharacterencoding ("GBK"); String StrName =new string (request.getparameter ("name"). GetBytes ("Iso-8859-1"), "UTF-8"); String Strchangs =new string (Request.getparameter ("Changs"). GetBytes ("Iso-8859-1"), "UTF-8"); String Strshoum =new string (Request.getparameter ("Shoum"). GetBytes ("Iso-8859-1"), "UTF-8"); String Strdizhi =new string (Request.getparameter ("Dizhi"). GetBytes ("Iso-8859-1"), "UTF-8"); if (StrName = = NULL | | Strname.trim (). Length () ==0) {Response.getwriter (). Append ("Product name cannot be empty"); } else if (strchangs = = NULL | | Strchangs.trim (). Length () ==0) {response.ge Twriter (). Append ("Commodity manufacturers cannot be empty"); } else if (Strshoum = = NULL | | Strshoum.trim (). Length () ==0) {response.getwriter (). AP Pend ("Service life cannot be empty"); } else if (Strdizhi = = NULL | | Strdizhi.trim (). Length () ==0) {Response.getwrite R (). Append ("Factory address cannot be empty"); } else {Response.getwriter (). Append ("Product Name:" + strName); Response.getwriter (). Append ("<BR>Commodity Manufacturers: "+strchangs); Response.getwriter (). Append ("<BR>Service Life: "+strshoum); Response.getwriter (). Append ("<BR>Factory Address: "+strdizhi"; }//response.getwriter (). Append ("Served at:asd"). Append (Request.getcontextpath ()). append (str); } else {Response.getwriter (). Append ("Served at:123"). Append (str); }}/** * @see httpservlet#dopost (httpservletrequest request, httpservletresponse response) */Protec Ted void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {// TODO auto-generated Method Stub doget (request, response); }}
Tijiao.java
Servlet Get product Information job