01: package forum;
02:
03: import java.io.*;
04: import javax.servlet.*;
05: import javax.servlet.http.*;
06: import java.util.*;
07: import java.sql.*;
08: import java.sql.Connection;
09: import java.sql.Statement;
10: import java.sql.ResultSet;
11:
12: public class AddForum extends HttpServlet {
13:
14: DBConnectie db = new DBConnectie(Variable.getDb(), Variable
15: .getDbLogin(), Variable.getDbPassword());
16:
17: public void doPost(HttpServletRequest request,
18: HttpServletResponse response) throws ServletException,
19: IOException {
20: PrintWriter out = response.getWriter();
21: try {
22:
23: int lastforum_id = Integer.parseInt(request
24: .getParameter("lastforum_id"));
25: String forum_id = Integer.toString(lastforum_id + 1);
26:
27: String title = request.getParameter("title");
28: if (title.equals("")) {
29: title = "No title";
30: } else {
31: title = Filter.filterAll(title);
32: }
33:
34: String forum_info = request.getParameter("forum_info");
35: forum_info = Filter.filterAll(forum_info);
36:
37: db.connect();
38:
39: db
40: .query("INSERT INTO forum_forums(forum_id,title,forum_info) "
41: + "VALUES(\""
42: + forum_id
43: + "\",\""
44: + title
45: + "\",\"" + forum_info + "\")");
46:
47: db.close();
48:
49: response
50: .sendRedirect(Variable.getForumPath() + "index.jsp");
51:
52: } catch (Exception e) {
53: out.println(e);
54: }
55:
56: }
57:
58: public void doGet(HttpServletRequest request,
59: HttpServletResponse response)//{
60: throws ServletException, IOException {
61: doPost(request, response);
62: }
63:
64: }
|