(1) The problem arises:
For the sake of simplicity we need a technique that can submit the form data all at once, that is to say: the Bean form
(2) The Beanutilities code is as follows:
Package Com.lc.ch04biaodanshuju;import Java.util.*;import Javax.servlet.http.*;import Org.apache.commons.beanutils.beanutils;public class Beanutilities {public static void Populatebean (Object Formbean, httpservletrequest request) { Populatebean (Formbean, Request.getparametermap ()); } public static void Populatebean (Object bean, Map propertymap) { try { beanutils.populate (bean, PropertyMap ); } catch (Exception e) { //Empty catch. The possible exceptions is //java.lang.IllegalAccessException and/ / Java.lang.reflect.InvocationTargetException. In both cases, just skip the bean operation.}}}
(3) A servlet that collects insurance employee insurance information is used to determine a workable insurance plan and related costs.
Package Com.lc.ch04biaodanshuju;import Java.io.ioexception;import Java.io.printwriter;import Javax.servlet.servletexception;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;public Class Submitinsuranceinfo extends HttpServlet {public void doget (HttpServletRequest request, Httpservletres Ponse response) throws Servletexception, IOException {insuranceinfo info = new Insuranceinfo (); Beanutilities.populatebean (info, request); Response.setcontenttype ("text/html"); PrintWriter out = Response.getwriter (); String DocType = "<! DOCTYPE HTML public \ "-//W3C//DTD HTML 4.0" + "transitional//en\" >\n "; String title = "Insurance Info for" + info.getname (); Out.println (DocType + "(4) JavaBean of connected database
Package Com.lc.ch04biaodanshuju;public class Insuranceinfo { private String name = "No name specified"; Private String EmployeeID = "No ID specified"; private int numchildren = 0; Private Boolean ismarried = false; Public String GetName () { return (name); } public void SetName (String name) { this.name = servletutilities.filter (name); } Public String Getemployeeid () { return (EmployeeID); } public void Setemployeeid (String employeeID) { This.employeeid = Servletutilities.filter (EmployeeID); } public int Getnumchildren () { return (Numchildren); } public void Setnumchildren (int numchildren) { this.numchildren = Numchildren; } public Boolean ismarried () { return (ismarried); } public void Setmarried (Boolean ismarried) { this.ismarried = ismarried; }}
(5)
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
(6) Jar package acquisition and use: we want to use the tool class must learn the jar package,: http://download.csdn.net/detail/u010870518/7867181 don't forget to add the configuration!
Jsp/servlet automatically populates Java objects with request parameters: Form Bean