KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > exceptions > CheckingServlet


1 /*
2  * CheckingServlet.java
3  *
4  * Created on January 16, 2007, 1:24 PM
5  */

6
7 package org.netbeans.modules.exceptions;
8
9 import java.io.DataInputStream JavaDoc;
10 import java.io.DataOutputStream JavaDoc;
11 import java.io.IOException JavaDoc;
12 import java.io.PrintWriter JavaDoc;
13 import java.sql.ResultSet JavaDoc;
14 import java.sql.SQLException JavaDoc;
15 import java.sql.Statement JavaDoc;
16 import java.util.logging.Level JavaDoc;
17 import java.util.logging.Logger JavaDoc;
18 import javax.servlet.*;
19 import javax.servlet.http.*;
20
21 /**
22  *
23  * @author jindra
24  * @version
25  */

26 public class CheckingServlet extends HttpServlet {
27     /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
28      * @param request servlet request
29      * @param response servlet response
30      */

31     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
32             throws ServletException, IOException JavaDoc {
33         response.setContentType("text/html;charset=UTF-8");
34         PrintWriter JavaDoc out = response.getWriter();
35         /* TODO output your page here
36         out.println("<html>");
37         out.println("<head>");
38         out.println("<title>Servlet CheckingServlet</title>");
39         out.println("</head>");
40         out.println("<body>");
41         out.println("<h1>Servlet CheckingServlet at " + request.getContextPath () + "</h1>");
42         out.println("</body>");
43         out.println("</html>");
44          */

45         out.close();
46     }
47     
48     protected void doPut(HttpServletRequest request, HttpServletResponse response)
49             throws ServletException, IOException JavaDoc {
50         try{
51             DataInputStream JavaDoc istream = new DataInputStream JavaDoc(request.getInputStream());
52             int vstup = istream.readInt();
53             Statement JavaDoc stmt = Utils.getConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
54             String JavaDoc query = Utils.SELECT_HASH+Integer.toString(vstup);
55             ResultSet JavaDoc result = Utils.executeQuery(stmt, query);
56             boolean found = result.next();
57             int issueId=0;
58             DataOutputStream JavaDoc resp = new DataOutputStream JavaDoc(response.getOutputStream());
59             if (found){
60                 issueId = result.getInt(2);
61                 resp.writeInt(issueId);
62                 Logger.getLogger(LoadingServlet.class.getName()).log(Level.FINEST,
63                         "Throwable "+Integer.toString(issueId) +" was checked");
64             } else{
65                 resp.writeInt(-1);// not found
66
Logger.getLogger(LoadingServlet.class.getName()).log(Level.FINER,
67                         "Throwable not found");
68             }
69             stmt.close();
70             resp.flush();
71             resp.close();
72         } catch (IOException JavaDoc ex) {
73             java.util.logging.Logger.getLogger(ComponentsServlet.class.getName()).log(java.util.logging.Level.SEVERE,
74                     ex.getMessage(), ex);
75         } catch (SQLException JavaDoc ex) {
76             java.util.logging.Logger.getLogger(ComponentsServlet.class.getName()).log(java.util.logging.Level.SEVERE,
77                     ex.getMessage(), ex);
78         };
79     }
80     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
81
/** Handles the HTTP <code>GET</code> method.
82      * @param request servlet request
83      * @param response servlet response
84      */

85     protected void doGet(HttpServletRequest request, HttpServletResponse response)
86             throws ServletException, IOException JavaDoc {
87         processRequest(request, response);
88     }
89     
90     /** Handles the HTTP <code>POST</code> method.
91      * @param request servlet request
92      * @param response servlet response
93      */

94     protected void doPost(HttpServletRequest request, HttpServletResponse response)
95             throws ServletException, IOException JavaDoc {
96         processRequest(request, response);
97     }
98     
99     /** Returns a short description of the servlet.
100      */

101     public String JavaDoc getServletInfo() {
102         return "Short description";
103     }
104     // </editor-fold>
105
}
106
Popular Tags