??? Today i write a servlet for auction. There are four steps we should do .
          1: fill BitInfo object by request parametes,and we can chage the type by BeanUtilities.populate.
          2.check BidInfo object if empty(all the parametes has default values and never change). if the object is empty,transfer showEmpty() and show the begin table.
          3.check BidInfo object if? partly empty(some parameter has changed and not all).if this ,transfer showEntryForm and give warnning.
          4.check BidInfo object if fill completely! if fill completely ,transfer showBid() for data deal.

          The Whole Code:
          BidServlet.java
          ?
          package skyey.snow.*;

          import? java.io.*;
          impot?? javax.servlet.*;
          import? javax.servlet.http.*;
          import? skyey.snow.*;
          public class BidServlet extends HttpServelt
          {
          ???? public void doGet(HttpServletResponse response,HttpServletRequest request)throws?ServletException,IOException
          ????? {
          ???????? BidInfo bid=new BidInfo();
          ???????? BeanUtilites.populateBean(bid,request);
          ???????? if(bid.isCompulete())
          ?????????? {
          ????????????? showBid(reqest,response,bid);
          ?????????? }
          ???????? else
          ?????????? {
          ?????????????? showEntryForm(request,response,bid);
          ??????????? }
          ????? }?
          /** All required data is present: show the results page.*/
          public void showBid(HttpServletRequest request,HttpServletResponse response,BidInfo bid)throws ServletException,IOException
          ?? {
          ???????submit(bit);
          ?????? response.setContentType("text/html);
          ?????? PrintWriter out=response.getWriter();
          ?????? String title="Bid Submitted";
          ?????? out.println(
          ?????????????????????? DOCTYPE+
          ??????????????????????? "<HTML>\n"+
          ???????????????????????? "<HEAD><TITLE>"+title+"</TITLE></HEAD>\n"+
          ????????????????????????? "<BODY BGCOLOR=\"#FDF5E6\"><CENTER>\n"+
          ???????????????????????????"<H1>"+title+"</H1>\n"+
          ??????????????????????????"Your bid is now active.If your bid is sucessful,\n"+
          ????????????????????????? "you will be notified within 24 hours of the close\n"+
          ????????????????????????? "of bidding.\n"+
          ????????????????????????? "<p>\n"+
          ????????????????????????? "<TABLE BORDER=1>\n"+
          ??????????????????????????"<TR><TH BGCOLOR=\"BLACK\"><FONT COLOR=\"WITHE\">"+
          ????????????????????????? bid.getItemName()+"</FONT>\n"+
          ??????????????????????????"<TR><TH>Item ID:"+
          ??????????????????????????bid.getItemID()+"\n"+
          ????????????????????????? .......................(省略一些))
          ?? }
          public void showEnteryForm(HttpServletRequest request,HttpServletResponse response,BidInfo bid)throws ServletException,IOException
          ? {
          ????? boolean isPartlyComplete=bid.isPartlyComplete();
          ????? rsponse.setContentType("text/html);
          ????? PrintWriter out=response.getWriter();
          ????? String title="";
          ............
          ? }
          private String inputElement(String prompt,String name,String value,boolean shouldPrompt)
          ?{
          ???? ......................
          ?}
          }

          BidInfo.java
          code:
          package skyey.snow.*;

          import skyey.snow.*;
          public class BidInfo
          {
          ?? private String itemID="";
          ?? private String itemName="";
          ?? private String bidderName="";
          ?? private String emailAddress="";
          ?? private double bidPrice=0;
          ?? private boolean autoIncrement=false;?
          public void set itemID(String itemID)
          ? {
          ????? this.itemID=ServletUtilities.fileter(itemID);
          ??}
          public String getItemID()
          ?{
          ???? return(itemID);
          ?}
          ......
          public boolean isComplete()
          ?{
          ??? return(hasValue(getItemID())&&
          ?????????????? hasValue(getItemName())&&
          ???????????????hsaValue(getBidderName())&&
          ?????????????? ......
          ???????????????(getBidPrice()>0))
          ?}
          public boolean isPartlyCompelet()
          ? {
          ??????? boolean flag=
          ??????????????????????????? (hasValue(getItemID()||
          ????????????????????????????? hasValue(getItemName())||
          ???????????????????????????? ......
          ??????????????????????????? (getBitPrice()>0))

          ?? }
          private boolean hasValue(String val)
          ?{
          ??? return((val!=null)&&(!val.equals("));
          ?}
          }
          posted on 2006-03-23 19:28 飛揚(yáng) 閱讀(154) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          統(tǒng)計(jì)

          FAQ網(wǎng)站

          JSP/Java/Servlet開(kāi)發(fā)工具

          JSP/Java/Servlet技術(shù)著名網(wǎng)站

          JSP/Servlet應(yīng)用程序站點(diǎn)

          優(yōu)選博客

          主站蜘蛛池模板: 翁牛特旗| 邮箱| 麻阳| 翁源县| 崇明县| 南涧| 锡林郭勒盟| 木兰县| 瑞丽市| 安平县| 武乡县| 绥中县| 莲花县| 公主岭市| 绵阳市| 建始县| 泗水县| 大冶市| 宝丰县| 永吉县| 黔西| 澄迈县| 双峰县| 静安区| 南投市| 惠东县| 唐山市| 昭通市| 瓦房店市| 宁强县| 额济纳旗| 镇坪县| 苏尼特右旗| 朝阳市| 竹山县| 石门县| 永德县| 普兰县| 河东区| 盐城市| 南安市|