??? 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開發(fā)工具

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

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

          優(yōu)選博客

          主站蜘蛛池模板: 鄢陵县| 竹山县| 武定县| 南和县| 桐城市| 遵义市| 于都县| 策勒县| 淮南市| 西昌市| 阿克| 陈巴尔虎旗| 宜川县| 勃利县| 平舆县| 绥阳县| 成武县| 永春县| 濉溪县| 赞皇县| 奉贤区| 汽车| 丹凤县| 开封县| 清苑县| 新野县| 高密市| 临潭县| 海丰县| 胶南市| 桓仁| 荥阳市| 阿瓦提县| 灌南县| 双桥区| 泸定县| 长顺县| 潞西市| 大方县| 西安市| 镇远县|