Biblioteca Java - Blame information for rev 33
Subversion Repositories:
(root)/Courses and labs samples/SCD/Video_tutorials_servlets/WebCalculator/src/java/com/utcn/aut/servlet/AdunaServlet.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 com.utcn.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 AdunaServlet extends HttpServlet { | ||
20 | |||
21 | /** | ||
22 | * Processes requests for both HTTP <code>GET</code> and <code>POST</code> | ||
23 | * methods. | ||
24 | * | ||
25 | * @param request servlet request | ||
26 | * @param response servlet response | ||
27 | * @throws ServletException if a servlet-specific error occurs | ||
28 | * @throws IOException if an I/O error occurs | ||
29 | */ | ||
30 | protected void processRequest(HttpServletRequest request, HttpServletResponse response) | ||
31 | throws ServletException, IOException { | ||
32 | response.setContentType("text/html;charset=UTF-8"); | ||
33 | try (PrintWriter out = response.getWriter()) { | ||
34 | /* TODO output your page here. You may use following sample code. */ | ||
35 | String op1 = request.getParameter("operand1"); | ||
36 | String op2 = request.getParameter("operand2"); | ||
37 | int rezultat = Integer.parseInt(op1) + Integer.parseInt(op2); | ||
38 | out.println("<!DOCTYPE html>"); | ||
39 | out.println("<html>"); | ||
40 | out.println("<head>"); | ||
41 | out.println("<title>Servlet AdunaServlet</title>"); | ||
42 | out.println("</head>"); | ||
43 | out.println("<body>"); | ||
44 | out.println("<h1>Rezultatul este " + rezultat + "</h1>"); | ||
45 | out.println("</body>"); | ||
46 | out.println("</html>"); | ||
47 | } | ||
48 | } | ||
49 | |||
50 | // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> | ||
51 | /** | ||
52 | * Handles the HTTP <code>GET</code> method. | ||
53 | * | ||
54 | * @param request servlet request | ||
55 | * @param response servlet response | ||
56 | * @throws ServletException if a servlet-specific error occurs | ||
57 | * @throws IOException if an I/O error occurs | ||
58 | */ | ||
59 | @Override | ||
60 | protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
61 | throws ServletException, IOException { | ||
62 | processRequest(request, response); | ||
63 | } | ||
64 | |||
65 | /** | ||
66 | * Handles the HTTP <code>POST</code> method. | ||
67 | * | ||
68 | * @param request servlet request | ||
69 | * @param response servlet response | ||
70 | * @throws ServletException if a servlet-specific error occurs | ||
71 | * @throws IOException if an I/O error occurs | ||
72 | */ | ||
73 | @Override | ||
74 | protected void doPost(HttpServletRequest request, HttpServletResponse response) | ||
75 | throws ServletException, IOException { | ||
76 | processRequest(request, response); | ||
77 | } | ||
78 | |||
79 | /** | ||
80 | * Returns a short description of the servlet. | ||
81 | * | ||
82 | * @return a String containing servlet description | ||
83 | */ | ||
84 | @Override | ||
85 | public String getServletInfo() { | ||
86 | return "Short description"; | ||
87 | }// </editor-fold> | ||
88 | |||
89 | } |