KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > rubis > beans > servlets > SellItemForm


1 package edu.rice.rubis.beans.servlets;
2
3 import java.io.IOException JavaDoc;
4
5 import javax.naming.Context JavaDoc;
6 import javax.naming.InitialContext JavaDoc;
7 import javax.servlet.ServletException JavaDoc;
8 import javax.servlet.http.HttpServlet JavaDoc;
9 import javax.servlet.http.HttpServletRequest JavaDoc;
10 import javax.servlet.http.HttpServletResponse JavaDoc;
11
12 /**
13  * Builds the html page that display the form to register a new item to sell.
14  * @author <a HREF="mailto:cecchet@rice.edu">Emmanuel Cecchet</a> and <a HREF="mailto:julie.marguerite@inrialpes.fr">Julie Marguerite</a>
15  * @version 1.0
16  */

17 public class SellItemForm extends HttpServlet JavaDoc
18 {
19   
20   /**
21    * Call the <code>doGet</code> method.
22    *
23    * @param request a <code>HttpServletRequest</code> value
24    * @param response a <code>HttpServletResponse</code> value
25    * @exception IOException if an error occurs
26    * @exception ServletException if an error occurs
27    */

28   public void doPost(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws IOException JavaDoc, ServletException JavaDoc
29   {
30     doGet(request, response);
31   }
32
33   /**
34    * Build the html page for the response
35    *
36    * @param request a <code>HttpServletRequest</code> value
37    * @param response a <code>HttpServletResponse</code> value
38    * @exception IOException if an error occurs
39    * @exception ServletException if an error occurs
40    */

41   public void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws IOException JavaDoc, ServletException JavaDoc
42   {
43     ServletPrinter sp = null;
44     String JavaDoc categoryId=null, userId=null;
45     Context JavaDoc initialContext = null;
46
47     sp = new ServletPrinter(response, "SellItemForm");
48     sp.printHTMLheader("RUBiS: Sell your item");
49
50     try
51     {
52       initialContext = new InitialContext JavaDoc();
53     }
54     catch (Exception JavaDoc e)
55     {
56       sp.printHTMLheader("RUBiS ERROR: SellItemForm");
57       sp.printHTML("Cannot get initial context for JNDI: " +e+"<br>");
58       sp.printHTMLfooter();
59       return ;
60     }
61
62     categoryId = request.getParameter("category");
63     userId = request.getParameter("user");
64     if ((categoryId == null) || categoryId.equals("") || (userId == null) || userId.equals(""))
65     {
66       sp.printHTMLheader("RUBiS ERROR: SellItemForm");
67       sp.printHTML("No category or user identifier received - Cannot process the request<br>");
68       sp.printHTMLfooter();
69       return ;
70     }
71     
72     sp.printFile(Config.HTMLFilesPath+"/sellItemForm.html");
73     sp.printHTML("<input type=hidden name=\"userId\" value=\""+userId+"\"> ");
74     sp.printHTML("<input type=hidden name=\"categoryId\" value=\""+categoryId+"\"> ");
75     sp.printHTMLfooter();
76   }
77 }
78
Popular Tags