Biblioteca Java - Blame information for rev 33
Subversion Repositories:
(root)/Courses and labs samples/SCD/Video_tutorials_servlets/WebHelloWorld/src/java/ro/utcluj/aut/servlet/HelloServlet.java
Rev | Author | Line No. | Line |
---|---|---|---|
33 | mihai | 1 | /* |
2 | * To change this license header, choose License Headers in Project Properties. | ||
3 | * To change this template file, choose Tools | Templates | ||
4 | * and open the template in the editor. | ||
5 | */ | ||
6 | package ro.utcluj.aut.servlet; | ||
7 | |||
8 | import java.io.IOException; | ||
9 | import java.io.PrintWriter; | ||
10 | import javax.servlet.ServletException; | ||
11 | import javax.servlet.http.HttpServlet; | ||
12 | import javax.servlet.http.HttpServletRequest; | ||
13 | import javax.servlet.http.HttpServletResponse; | ||
14 | |||
15 | /** | ||
16 | * | ||
17 | * @author mihai | ||
18 | */ | ||
19 | public class HelloServlet extends HttpServlet { | ||
20 | |||
21 | int counter = 0; | ||
22 | |||
23 | /** | ||
24 | * Processes requests for both HTTP <code>GET</code> and <code>POST</code> | ||
25 | * methods. | ||
26 | * | ||
27 | * @param request servlet request | ||
28 | * @param response servlet response | ||
29 | * @throws ServletException if a servlet-specific error occurs | ||
30 | * @throws IOException if an I/O error occurs | ||
31 | */ | ||
32 | protected void processRequest(HttpServletRequest request, HttpServletResponse response) | ||
33 | throws ServletException, IOException { | ||
34 | response.setContentType("text/html;charset=UTF-8"); | ||
35 | counter++; | ||
36 | try (PrintWriter out = response.getWriter()) { | ||
37 | /* TODO output your page here. You may use following sample code. */ | ||
38 | out.println("<!DOCTYPE html>"); | ||
39 | out.println("<html>"); | ||
40 | out.println("<head>"); | ||
41 | out.println("<title>Servlet HelloServlet</title>"); | ||
42 | out.println("</head>"); | ||
43 | out.println("<body>"); | ||
44 | out.println("<h1>Servlet HelloServlet at " + request.getContextPath() + "</h1>"); | ||
45 | out.println("<h2>Counter is" + counter + "</h2>"); | ||
46 | out.println("</body>"); | ||
47 | out.println("</html>"); | ||
48 | } | ||
49 | } | ||
50 | |||
51 | // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> | ||
52 | /** | ||
53 | * Handles the HTTP <code>GET</code> method. | ||
54 | * | ||
55 | * @param request servlet request | ||
56 | * @param response servlet response | ||
57 | * @throws ServletException if a servlet-specific error occurs | ||
58 | * @throws IOException if an I/O error occurs | ||
59 | */ | ||
60 | @Override | ||
61 | protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
62 | throws ServletException, IOException { | ||
63 | processRequest(request, response); | ||
64 | } | ||
65 | |||
66 | /** | ||
67 | * Handles the HTTP <code>POST</code> method. | ||
68 | * | ||
69 | * @param request servlet request | ||
70 | * @param response servlet response | ||
71 | * @throws ServletException if a servlet-specific error occurs | ||
72 | * @throws IOException if an I/O error occurs | ||
73 | */ | ||
74 | @Override | ||
75 | protected void doPost(HttpServletRequest request, HttpServletResponse response) | ||
76 | throws ServletException, IOException { | ||
77 | processRequest(request, response); | ||
78 | } | ||
79 | |||
80 | /** | ||
81 | * Returns a short description of the servlet. | ||
82 | * | ||
83 | * @return a String containing servlet description | ||
84 | */ | ||
85 | @Override | ||
86 | public String getServletInfo() { | ||
87 | return "Short description"; | ||
88 | }// </editor-fold> | ||
89 | |||
90 | } |