10 thoughts on “Database Login Form in Jsp and Servlet

  • December 10, 2017 at 2:39 pm
    Permalink

    Why it's not redirect to welcome.jsp?

    Reply
  • January 29, 2019 at 11:51 am
    Permalink

    Yes ! I Have the Same Problem as @daru Daru…
    why it's not redirected to welcome.jsp?

    Reply
  • January 29, 2019 at 1:07 pm
    Permalink

    voice no why

    Reply
  • February 13, 2019 at 5:29 am
    Permalink

    y los estilos?

    Reply
  • March 11, 2019 at 8:09 pm
    Permalink

    Fake don't happen anything 🙅🙅🙅

    Reply
  • April 15, 2019 at 8:55 pm
    Permalink

    please add voice

    Reply
  • April 24, 2019 at 9:31 pm
    Permalink

    whats the controller class doing? i thought when a user logs in he should be able to see his details not only a message. And how do you insure that not just anyone can log in?
    please help, this was not that helpful, but thanks, please explain what the control serlet is doing……..

    Reply
  • January 30, 2020 at 12:20 am
    Permalink

    I don't know why it is not working . Can you check this ?

    Login.java
    ———————————————————————————————————–
    package com.dao;

    import java.io.IOException;

    import java.io.PrintWriter;

    import javax.servlet.RequestDispatcher;

    import javax.servlet.ServletException;

    import javax.servlet.annotation.WebServlet;

    import javax.servlet.http.HttpServlet;

    import javax.servlet.http.HttpServletRequest;

    import javax.servlet.http.HttpServletResponse;

    import javax.servlet.http.HttpSession;

    @WebServlet("/login")

    public class login_patient extends HttpServlet {

    private static final long serialVersionUID = 1L;

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    // TODO Auto-generated method stub

    PrintWriter out = response.getWriter();

    String email , pass;

    email = request.getParameter("email");

    pass = request.getParameter("pass");

    if(LoginDao.checkvalidate(email, pass)) {

    RequestDispatcher rs = request.getRequestDispatcher("welcomepatient.jsp");

    HttpSession session = request.getSession();

    session.setAttribute("email", email);

    rs.forward(request, response);

    }

    else {

    response.sendRedirect("patientinfo.jsp");

    }

    }

    }

    —————————————————————–LoginDao.java————————————————————————————————-
    package com.dao;

    import java.sql.*;

    public class LoginDao {

    public static boolean checkvalidate(String email, String pass) {

    boolean status = false;

    try {

    Class.forName("com.mysql.jdbc.Driver");

    Connection con=DriverManager.getConnection(

    "jdbc:mysql://localhost:3306/project","root","root");

    //here project is database name, root is username and password

    PreparedStatement stmt = con.prepareStatement("select * from register where email=? and pass=?");

    stmt.setString(1, email);

    stmt.setString(2, pass);

    ResultSet rs = stmt.executeQuery();

    status = rs.next();

    con.close();

    }catch (Exception e) {

    e.getMessage();

    }

    return status;

    }

    }

    Reply
  • February 3, 2020 at 1:01 pm
    Permalink

    What is durgesh in connection link? Is it database name?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *