2 * To change this template, choose Tools | Templates
\r
3 * and open the template in the editor.
\r
5 package org.ufcspa.simdecs.comunicacao;
\r
7 import java.io.IOException;
\r
8 import java.io.PrintWriter;
\r
9 import javax.servlet.ServletException;
\r
10 import javax.servlet.http.HttpServlet;
\r
11 import javax.servlet.http.HttpServletRequest;
\r
12 import javax.servlet.http.HttpServletResponse;
\r
13 import javax.servlet.*;
\r
15 import javax.persistence.EntityManager;
\r
16 import javax.persistence.EntityManagerFactory;
\r
17 import javax.persistence.NoResultException;
\r
18 import javax.persistence.Persistence;
\r
19 import javax.servlet.http.*;
\r
20 import org.ufcspa.simdecs.entidade.Log;
\r
21 import org.ufcspa.simdecs.entidade.Usuario;
\r
28 public class MetodoAutenticacao extends HttpServlet {
\r
31 * Processes requests for both HTTP
\r
32 * <code>GET</code> and
\r
33 * <code>POST</code> methods.
\r
35 * @param request servlet request
\r
36 * @param response servlet response
\r
37 * @throws ServletException if a servlet-specific error occurs
\r
38 * @throws IOException if an I/O error occurs
\r
40 private ServletConfig config;
\r
41 public void init(ServletConfig config)
\r
42 throws ServletException{
\r
45 protected void processRequest(HttpServletRequest request, HttpServletResponse response)
\r
46 throws ServletException, IOException {
\r
48 PrintWriter out = response.getWriter();
\r
49 // alteracao solicitado mosmmann
\r
50 //response.setContentType("text/html;charset=UTF-8");
\r
52 response.setContentType( "text/xml" );
\r
53 response.setHeader( "Cache-Control", "no-cache" );
\r
54 ///para devolver arquivo anexo
\r
55 //response.addHeader("Content-Disposition", "attachment; filename="+ "teste");
\r
56 //response.setContentType("text/html;charset=UTF-8");
\r
59 //PrintWriter out = response.getWriter();
\r
60 EntityManagerFactory emf = Persistence.createEntityManagerFactory("simdecsPU");
\r
61 EntityManager em = emf.createEntityManager();
\r
62 out.println( "<xml>" );
\r
66 user = (Usuario) em.createQuery("select usu from Usuario as usu where usu.login=:login and usu.senha=:senha")
\r
67 .setParameter("login", request.getParameter("user"))
\r
68 .setParameter("senha", request.getParameter("pass"))
\r
69 .getSingleResult();
\r
71 out.println( "<id>" + String.valueOf(user.getId()) + "</id>" );
\r
72 // out.println("OK "+ user.getId());
\r
74 } catch (NoResultException ne) {
\r
76 // request.setAttribute("id","0");
\r
77 // out.println("Usuario ou senha Inválido ");
\r
78 out.println( "<id>" + "0" + "</id>" );
\r
81 out.println( "</xml>" );
\r
86 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
\r
89 * <code>GET</code> method.
\r
91 * @param request servlet request
\r
92 * @param response servlet response
\r
93 * @throws ServletException if a servlet-specific error occurs
\r
94 * @throws IOException if an I/O error occurs
\r
97 protected void doGet(HttpServletRequest request, HttpServletResponse response)
\r
98 throws ServletException, IOException {
\r
99 processRequest(request, response);
\r
104 * <code>POST</code> method.
\r
106 * @param request servlet request
\r
107 * @param response servlet response
\r
108 * @throws ServletException if a servlet-specific error occurs
\r
109 * @throws IOException if an I/O error occurs
\r
112 protected void doPost(HttpServletRequest request, HttpServletResponse response)
\r
113 throws ServletException, IOException {
\r
114 processRequest(request, response);
\r
118 * Returns a short description of the servlet.
\r
120 * @return a String containing servlet description
\r
123 public String getServletInfo() {
\r
124 return "Short description";
\r