(1) In some cases, we need to fill out the form, but did not fill in the submission, we need to keep the completed data and then let the user fill in the non-filled data
(2) To implement the function with a servlet that deals with auction bids:
Bidinfo.java
Package Com.lc.ch04jingbiao;import Com.lc.ch04biaodanshuju.servletutilities;public class Bidinfo {private String ItemID = ""; Private String ItemName = ""; Private String Biddername = ""; Private String EmailAddress = ""; Private double bidprice = 0; Private Boolean autoincrement = false; Public String Getitemname () {return (itemname); } public void Setitemname (String itemname) {this.itemname = Servletutilities.filter (itemname); } public String Getitemid () {return (ItemID); } public void Setitemid (String itemID) {this.itemid = Servletutilities.filter (ItemID); } public String Getbiddername () {return (biddername); } public void Setbiddername (String biddername) {this.biddername = Servletutilities.filter (biddername); } public String getemailaddress () {return (EmailAddress); } public void Setemailaddress (String emailaddress) {this.emailaddress = Servletutilities.filter (EmailAddress); } public double Getbidprice () {return (bidprice); } public void Setbidprice (double bidprice) {this.bidprice = Bidprice; } public boolean isautoincrement () {return (AutoIncrement); The public void Setautoincrement (Boolean autoincrement) {this.autoincrement = AutoIncrement; }/** to determine whether to complete/public boolean iscomplete () {return (HasValue (Getitemid ()) && HasValue (Getitemname ( )) && HasValue (Getbiddername ()) && HasValue (getemailaddress ()) && (g Etbidprice () > 0)); }//determine if there are no entries filled in public boolean ispartlycomplete () {Boolean flag = (HasValue (Getitemid ()) | | HasValue (Getitemname ()) | | HasValue (Getbiddername ()) | | HasValue (Getemailaddress ()) | | (Getbidprice () > 0) | | Isautoincrement ()); return (flag); } Private Boolean HasValue (String val) {return ((val! = null) && (!val.equals ("")); }}
The Bidservlet code is as follows:
Package Com.lc.ch04jingbiao;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;import Com.lc.ch04biaodanshuju.beanutilities;public class Bidservlet extends HttpServlet {public void doget ( HttpServletRequest request, HttpServletResponse response) throws Servletexception, IOException { Bidinfo bid = new Bidinfo (); Beanutilities.populatebean (bid, request); if (Bid.iscomplete ()) {//All required form data is supplied:show result. Showbid (Request, response, bid); } else {//form data was missing or Incomplete:redisplay form. Showentryform (Request, response, bid); }}/** all required data is present:show the results page. */private void Showbid (HttpServletRequest request, httpservletresponse response, BidinfoBid) throws Servletexception, IOException {submitbid (BID); Response.setcontenttype ("text/html"); PrintWriter out = Response.getwriter (); String title = "Bid submitted"; Out.println (DOCTYPE + "
(3) After configuring the servlet, demonstrate the effect:
Fill out the form completely:
If the form is not fully populated:
Results after submission: (Prompt to fill in missing data)
Ok!
SERVLET/JSP implementation when parameters are true or missing re-display the input form