Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package modelos;
- import static java.lang.System.out;
- import java.sql.*;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class conexionBD{
- public Connection conex;
- public static final String CLASS="oracle.jdbc.OracleDriver";
- public static final String URL="jdbc:oracle:thin:@localhost:1521:XE";//url de nuestro odbc
- public static final String USUARIO="Agenda";
- public static final String CLAVE="wkprogra";
- public PreparedStatement consulta;
- public ResultSet rs;
- public void conectar(){
- try{
- Class.forName(CLASS);
- this.conex=DriverManager.getConnection(URL,USUARIO,CLAVE);
- } catch (SQLException | ClassNotFoundException ex) {
- Logger.getLogger(conexionBD.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- public void desconectar() throws SQLException {
- this.conex.close();
- }
- public boolean insert(String correo,String contrasena, String nombres, String apellidos) throws SQLException{
- this.conectar();
- boolean resultado=false;
- try{
- this.consulta = this.conex.prepareStatement("insert into usuarios(usuario_correo,usuario_contrasena,usuario_nombres,usuario_apellidos,fecha_registro)"
- + "values('"+correo+"','"+contrasena+"','"+nombres+"','"+apellidos+"',sysdate)");
- resultado =this.consulta.execute();
- return resultado;
- }catch(Exception ex){
- out.println(ex.getMessage());
- return false;
- }
- }
- }
- import java.sql.*;
- public class login {
- public boolean auntenticar(String correo,String contrasena) throws SQLException{
- boolean log;
- conexionBD conexion = new conexionBD();
- conexion.conectar();
- try{
- Statement st = conexion.conex.createStatement();
- ResultSet rs;
- rs = st.executeQuery("select * from usuarios where usuario_correo='" + correo + "' and usuario_contrasena='" + contrasena + "'");
- log = rs.next();
- return log;
- }catch(Exception ex){
- return false;
- }
- }
- import modelos.registrar;
- import modelos.login;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.io.Writer;
- import javax.servlet.ServletException;
- import javax.servlet.http.*;
- import java.sql.*;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class controlServlet extends HttpServlet {
- String activarUsuario;
- /**
- * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
- * methods.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- * @throws java.sql.SQLException
- */
- protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException
- {response.setContentType("text/html;charset=UTF-8");
- try (PrintWriter out = response.getWriter()) {
- /* TODO output your page here. You may use following sample code. */
- StringBuffer respuesta= new StringBuffer();
- Writer ajaxSalida= response.getWriter();
- String correo=request.getParameter("correo");
- String contrasena=request.getParameter("contrasena");
- login au=new login();
- if(au.auntenticar(correo,contrasena)){
- response.sendRedirect("home.jsp");
- }else{
- response.sendRedirect("index.html");
- }
- }
- }
- // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
- /**
- * Handles the HTTP <code>GET</code> method.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- @Override
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- try{
- processRequest(request, response);
- }catch(SQLException ex){
- Logger.getLogger(controlServlet.class.getName()).log(Level.SEVERE,null,ex);
- }
- }
- /**
- * Handles the HTTP <code>POST</code> method.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- @Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- try{
- processRequest(request, response);
- }catch(SQLException ex){
- Logger.getLogger(controlServlet.class.getName()).log(Level.SEVERE,null,ex);
- }
- }
- /**
- * Returns a short description of the servlet.
- *
- * @return a String containing servlet description
- */
- @Override
- public String getServletInfo() {
- return "Short description";
- }// </editor-fold>
- }
- import modelos.conexionBD;
- import java.io.IOException;
- import java.io.PrintWriter;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import modelos.consultas;
- import modelos.registrar;
- import java.io.Writer;
- import java.sql.*;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class goToSession extends HttpServlet {
- /**
- * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
- * methods.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- * @throws java.sql.SQLException
- */
- protected void processRequest(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException, SQLException {
- response.setContentType("text/html;charset=UTF-8");
- try (PrintWriter out = response.getWriter()) {
- /* TODO output your page here. You may use following sample code. */
- String correo=request.getParameter("correo2");
- String contrasena=request.getParameter("contrasena1");
- String nombres=request.getParameter("nombres");
- String apellidos=request.getParameter("apellidos");
- conexionBD au=new conexionBD();
- if(au.insert(correo, contrasena, nombres, apellidos)){
- response.sendRedirect("index.html");
- }else{
- response.getWriter().print("Error");
- }
- }
- }
- // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
- /**
- * Handles the HTTP <code>GET</code> method.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- @Override
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- try{
- processRequest(request, response);
- }catch(SQLException ex){
- Logger.getLogger(goToSession.class.getName()).log(Level.SEVERE,null,ex);
- }
- }
- /**
- * Handles the HTTP <code>POST</code> method.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- @Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- try{
- processRequest(request, response);
- }catch(SQLException ex){
- Logger.getLogger(goToSession.class.getName()).log(Level.SEVERE,null,ex);
- }
- }
- /**
- * Returns a short description of the servlet.
- *
- * @return a String containing servlet description
- */
- @Override
- public String getServletInfo() {return "Short description";
- }// </editor-fold>
- }
Add Comment
Please, Sign In to add comment