Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package miservlet;
- import com.sun.javafx.application.ParametersImpl;
- import java.io.*;
- import java.sql.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- /**
- *
- * @author javier.fernandez3
- */
- public class MiServlet extends HttpServlet {
- public void init(ServletConfig conf)throws ServletException{
- super.init(conf);//siempre para usar el objeto conf
- String driver=null;
- driver=conf.getInitParameter("cadenaDriver");//lee el param del web .xml
- //cargar el driver
- try{
- Class.forName(driver);
- }catch (ClassNotFoundException cne){
- }
- }
- /**
- *
- * @param peticion
- * @param respuesta
- * @throws ServletException
- * @throws IOException
- */
- public void doGet(HttpServletRequest peticion, HttpServletResponse respuesta)
- throws ServletException, IOException
- {
- //leer datos del formulario
- String usuario,clave;
- usuario=peticion.getParameter("user");
- clave=peticion.getParameter("pass");
- respuesta.setContentType("text/html");
- PrintWriter pw=respuesta.getWriter();
- Connection con= null;
- Statement st = null;
- ResultSet rs = null;
- //conectarnos
- try{
- con=DriverManager.getConnection("jdbc:mysql://localhost/usuarios","root","");
- pw.println("Conectados a usuarios...");
- }catch(SQLException sql){
- pw.println("ERROR DE CONEXION");
- }
- //crear el statement
- try {
- st=con.createStatement();
- } catch (SQLException sql) {
- }
- String sql ="select * from permisos where(usuario'"+usuario+"' AND clave='"+clave+"')";
- try {
- } catch (Exception e) {
- }
- {
- }
- //generar salida
- pw.println("<HTML>");
- pw.println("<BODY>");
- /* pw.println("<h1>Tus datos son:</h1>");
- pw.println("<hr>");
- pw.println("<h2> Usuario: " + usuario + "</h2>");
- pw.println("<h2> Password: " + clave + "</h2>");*/
- pw.println("</BODY>");
- pw.println("</HTML>");
- }
- public void doPost(HttpServletRequest peticion, HttpServletResponse respuesta)
- throws ServletException, IOException
- {
- doGet(peticion,respuesta);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement