KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > rubbos > servlets > PostComment


1 /**
2  * RUBBoS: Rice University Bulletin Board System.
3  * Copyright (C) 2001-2004 Rice University and French National Institute For
4  * Research In Computer Science And Control (INRIA).
5  * Contact: jmob@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Emmanuel Cecchet.
22  * Contributor(s): Niraj Tolia.
23  */

24
25 package edu.rice.rubbos.servlets;
26
27 import java.io.IOException JavaDoc;
28 import java.sql.Connection JavaDoc;
29 import java.sql.PreparedStatement JavaDoc;
30
31 import javax.servlet.ServletException JavaDoc;
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34
35 public class PostComment extends RubbosHttpServlet
36 {
37
38   public int getPoolSize()
39   {
40     return Config.BrowseCategoriesPoolSize;
41   }
42
43   private void closeConnection(PreparedStatement JavaDoc stmt, Connection JavaDoc conn)
44   {
45     try
46     {
47       if (stmt != null)
48         stmt.close(); // close statement
49
}
50     catch (Exception JavaDoc ignore)
51     {
52     }
53
54     try
55     {
56       if (conn != null)
57           releaseConnection(conn);
58     }
59     catch (Exception JavaDoc ignore)
60     {
61     }
62   }
63
64   /** Build the html page for the response */
65   public void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
66       throws IOException JavaDoc, ServletException JavaDoc
67   {
68
69     ServletPrinter sp = null;
70
71     sp = new ServletPrinter(response, "BrowseCategoriesByCategory");
72
73     String JavaDoc storyIdtest, categoryId, testparent, comment_table;
74     int parent = 0, storyId = 0;
75
76     storyIdtest = request.getParameter("storyId");
77     testparent = request.getParameter("parent");
78
79     if (storyIdtest != null)
80     {
81       storyId = (Integer.valueOf(request.getParameter("storyId"))).intValue();
82     }
83
84     if (testparent != null)
85     {
86       parent = (Integer.valueOf(request.getParameter("parent"))).intValue();
87     }
88
89     comment_table = request.getParameter("comment_table");
90
91     if (comment_table == null)
92     {
93       sp.printHTML("Viewing comment, You must provide a comment table!<br>");
94       return;
95     }
96
97     sp.printHTMLheader("RUBBoS: Comment submission");
98     sp
99         .printHTML("<p><br><center><h2>Post a comment !</h2><br>\n"
100             + "<form action=\"/rubbos/servlet/edu.rice.rubbos.servlets.StoreComment\" method=POST>\n"
101             + "<input type=hidden name=storyId value="
102             + storyId
103             + ">\n"
104             + "<input type=hidden name=parent value="
105             + parent
106             + ">\n"
107             + "<input type=hidden name=comment_table value="
108             + comment_table
109             + ">\n"
110             + "<center><table>\n"
111             + "<tr><td><b>Nickname</b><td><input type=text size=20 name=nickname>\n"
112             + "<tr><td><b>Password</b><td><input type=text size=20 name=password>\n"
113             + "<tr><td><b>Subject</b><td><input type=text size=100 name=subject>\n"
114             + "</SELECT></table><p><br>\n"
115             + "<TEXTAREA rows=\"20\" cols=\"80\" name=\"body\">Write your comment here</TEXTAREA><br><p>\n"
116             + "<input type=submit value=\"Post your comment now!\"></center><p>\n");
117
118     sp.printHTMLfooter();
119
120   }
121
122   public void doPost(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
123       throws IOException JavaDoc, ServletException JavaDoc
124   {
125     doGet(request, response);
126   }
127
128 }
129
Popular Tags