Advertisement
Guest User

Untitled

a guest
Oct 9th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  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 miservlet;
  7. import com.sun.javafx.application.ParametersImpl;
  8. import java.io.*;
  9. import java.sql.*;
  10. import javax.servlet.*;
  11. import javax.servlet.http.*;
  12.  
  13. /**
  14. *
  15. * @author javier.fernandez3
  16. */
  17. public class MiServlet extends HttpServlet {
  18.  
  19. public void init(ServletConfig conf)throws ServletException{
  20.  
  21. super.init(conf);//siempre para usar el objeto conf
  22. String driver=null;
  23. driver=conf.getInitParameter("cadenaDriver");//lee el param del web .xml
  24.  
  25. //cargar el driver
  26. try{
  27. Class.forName(driver);
  28. }catch (ClassNotFoundException cne){
  29.  
  30. }
  31. }
  32.  
  33. /**
  34. *
  35. * @param peticion
  36. * @param respuesta
  37. * @throws ServletException
  38. * @throws IOException
  39. */
  40. public void doGet(HttpServletRequest peticion, HttpServletResponse respuesta)
  41. throws ServletException, IOException
  42. {
  43.  
  44. //leer datos del formulario
  45.  
  46. String usuario,clave;
  47. usuario=peticion.getParameter("user");
  48. clave=peticion.getParameter("pass");
  49.  
  50. respuesta.setContentType("text/html");
  51. PrintWriter pw=respuesta.getWriter();
  52. Connection con= null;
  53. Statement st = null;
  54. ResultSet rs = null;
  55.  
  56.  
  57.  
  58.  
  59.  
  60. //conectarnos
  61.  
  62. try{
  63. con=DriverManager.getConnection("jdbc:mysql://localhost/usuarios","root","");
  64. pw.println("Conectados a usuarios...");
  65. }catch(SQLException sql){
  66. pw.println("ERROR DE CONEXION");
  67.  
  68. }
  69.  
  70. //crear el statement
  71. try {
  72. st=con.createStatement();
  73. } catch (SQLException sql) {
  74.  
  75. }
  76.  
  77. String sql ="select * from permisos where(usuario'"+usuario+"' AND clave='"+clave+"')";
  78.  
  79. try {
  80.  
  81. } catch (Exception e) {
  82. }
  83. {
  84.  
  85. }
  86.  
  87. //generar salida
  88.  
  89.  
  90. pw.println("<HTML>");
  91. pw.println("<BODY>");
  92. /* pw.println("<h1>Tus datos son:</h1>");
  93. pw.println("<hr>");
  94. pw.println("<h2> Usuario: " + usuario + "</h2>");
  95. pw.println("<h2> Password: " + clave + "</h2>");*/
  96. pw.println("</BODY>");
  97. pw.println("</HTML>");
  98.  
  99.  
  100. }
  101.  
  102.  
  103. public void doPost(HttpServletRequest peticion, HttpServletResponse respuesta)
  104. throws ServletException, IOException
  105. {
  106. doGet(peticion,respuesta);
  107. }
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement