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 飞扬 阅读(141) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 

统计

FAQ网站

JSP/Java/Servlet开发工具

JSP/Java/Servlet技术著名网站

JSP/Servlet应用程序站点

优选博客