Biblioteca Java - Blame information for rev 34

Subversion Repositories:
Rev:
Rev Author Line No. Line
34 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.ServletConfig;
11 import javax.servlet.ServletException;
12 import javax.servlet.annotation.WebServlet;
13 import javax.servlet.http.HttpServlet;
14 import javax.servlet.http.HttpServletRequest;
15 import javax.servlet.http.HttpServletResponse;
16  
17 /**
18  *
19  * @author mihai
20  */
21 @WebServlet(name = "HelloWorldServlet", urlPatterns = {"/HelloWorldServlet"})
22 public class HelloWorldServlet extends HttpServlet {
23  
24     @Override
25     public void init(ServletConfig config) throws ServletException {
26         this.getServletContext().log("Servlet initialised!");
27     }
28  
29     /**
30      * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
31      * methods.
32      *
33      * @param request servlet request
34      * @param response servlet response
35      * @throws ServletException if a servlet-specific error occurs
36      * @throws IOException if an I/O error occurs
37      */
38     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
39             throws ServletException, IOException {
40         response.setContentType("text/html;charset=UTF-8");
41         this.getServletContext().log("Call processing request!");
42         try (PrintWriter out = response.getWriter()) {
43             out.println("<!DOCTYPE html>");
44             out.println("<html>");
45             out.println("<head>");
46             out.println("<title>Servlet HelloWorldServlet</title>");            
47             out.println("</head>");
48             out.println("<body>");
49             out.println("<h1>Servlet HelloWorldServlet at " + request.getContextPath() + "</h1>");
50             out.println("</body>");
51             out.println("</html>");
52         }
53     }
54  
55     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
56     /**
57      * Handles the HTTP <code>GET</code> method.
58      *
59      * @param request servlet request
60      * @param response servlet response
61      * @throws ServletException if a servlet-specific error occurs
62      * @throws IOException if an I/O error occurs
63      */
64     @Override
65     protected void doGet(HttpServletRequest request, HttpServletResponse response)
66             throws ServletException, IOException {
67         processRequest(request, response);
68     }
69  
70     /**
71      * Handles the HTTP <code>POST</code> method.
72      *
73      * @param request servlet request
74      * @param response servlet response
75      * @throws ServletException if a servlet-specific error occurs
76      * @throws IOException if an I/O error occurs
77      */
78     @Override
79     protected void doPost(HttpServletRequest request, HttpServletResponse response)
80             throws ServletException, IOException {
81         processRequest(request, response);
82     }
83  
84     /**
85      * Returns a short description of the servlet.
86      *
87      * @return a String containing servlet description
88      */
89     @Override
90     public String getServletInfo() {
91         return "Short description";
92     }// </editor-fold>
93  
94 }