Biblioteca Java - Blame information for rev 33

Subversion Repositories:
Rev:
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 java.util.HashMap;
11 import java.util.Iterator;
12 import javax.servlet.ServletException;
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 public class PersoanaServlet extends HttpServlet {
22  
23      HashMap<String,String> persoane = new HashMap<>();
24  
25  
26     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
27     /**
28      * Handles the HTTP <code>GET</code> method.
29      *
30      * @param request servlet request
31      * @param response servlet response
32      * @throws ServletException if a servlet-specific error occurs
33      * @throws IOException if an I/O error occurs
34      */
35     @Override
36     protected void doGet(HttpServletRequest request, HttpServletResponse response)
37             throws ServletException, IOException {
38  
39         String nume = request.getParameter("nume");
40         System.err.println(nume);
41         String raspuns;
42         if(nume==null)
43             raspuns = "Parametrul nume nu a fost specificat.";
44         else{
45             if(persoane.containsKey(nume))
46                raspuns = "Varsta persoanei este="+persoane.get(nume);
47             else
48                raspuns = "Persoana nu a fost gasita.";
49         }
50         PrintWriter out = response.getWriter();
51         out.println("<!DOCTYPE html>");
52         out.println("<html>");
53         out.println("<head>");
54         out.println("<title>Servlet AdunaServlet</title>");            
55         out.println("</head>");
56         out.println("<body>");
57         out.println("<h1>"+raspuns+"</h1>");
58         out.println("</body>");
59         out.println("</html>");                
60     }
61  
62     /**
63      * Handles the HTTP <code>POST</code> method.
64      *
65      * @param request servlet request
66      * @param response servlet response
67      * @throws ServletException if a servlet-specific error occurs
68      * @throws IOException if an I/O error occurs
69      */
70     @Override
71     protected void doPost(HttpServletRequest request, HttpServletResponse response)
72             throws ServletException, IOException {
73  
74          String op1 = request.getParameter("nume");
75          String op2 = request.getParameter("varsta");
76          persoane.put(op1, op2);
77          PrintWriter out = response.getWriter();
78          out.println("<!DOCTYPE html>");
79             out.println("<html>");
80             out.println("<head>");
81             out.println("<title>Servlet AdunaServlet</title>");            
82             out.println("</head>");
83             out.println("<body>");
84             out.println("<h1> Persoana a fost adaugata</h1>");
85             out.println("<h1> Numar total de persoane:"+persoane.size()+"</h1>");
86             out.println("</body>");
87             out.println("</html>");
88  
89     }
90  
91     /**
92      * Returns a short description of the servlet.
93      *
94      * @return a String containing servlet description
95      */
96     @Override
97     public String getServletInfo() {
98         return "Short description";
99     }// </editor-fold>
100  
101 }