KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > web > Test


1 /*
2  * Test.java
3  *
4  * Created on November 21, 2005, 12:19 PM
5  */

6
7 package web;
8
9 import java.io.*;
10 import java.net.*;
11
12 import javax.servlet.*;
13 import javax.servlet.http.*;
14
15 /**
16  *
17  * @author serj
18  * @version
19  */

20 public class Test extends HttpServlet {
21     
22     /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
23      * @param request servlet request
24      * @param response servlet response
25      */

26     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
27     throws ServletException, IOException {
28         response.setContentType("text/html;charset=UTF-8");
29         PrintWriter out = response.getWriter();
30
31         out.println("<html>");
32         out.println("<head>");
33         out.println("<title>Servlet Test</title>");
34         out.println("</head>");
35         out.println("<body>");
36         out.println("<h1>Servlet Test at " + request.getContextPath () + "</h1>");
37         out.println("</body>");
38         out.println("</html>");
39
40         out.close();
41     }
42     
43     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
44
/** Handles the HTTP <code>GET</code> method.
45      * @param request servlet request
46      * @param response servlet response
47      */

48     protected void doGet(HttpServletRequest request, HttpServletResponse response)
49     throws ServletException, IOException {
50         processRequest(request, response);
51     }
52     
53     /** Handles the HTTP <code>POST</code> method.
54      * @param request servlet request
55      * @param response servlet response
56      */

57     protected void doPost(HttpServletRequest request, HttpServletResponse response)
58     throws ServletException, IOException {
59         processRequest(request, response);
60     }
61     
62     /** Returns a short description of the servlet.
63      */

64     public String JavaDoc getServletInfo() {
65         return "Short description";
66     }
67     // </editor-fold>
68
}
69
Popular Tags