How to create Login Form in JSP Web page,Login Form Tutorial in JSP Web Page

1)  Create Table using Mysql Server 
     create table admin(username varchar(50),password varchar(50))
       insert  into admin values('admin',12345);
2)  Create Form in Jsp for login
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <form action="AdminSer" method="post">
            <p><input type="text" name="txtuser" placeholder="Enter username" /></p>
            <p><input type="password" name="txtpass" placeholder="Enter password" /></p>
            <p><input type="submit" name="btnsubmit" value="Login" /> </p>
3)  Create Servlet for admin login and write database code
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class AdminSer extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
       try (PrintWriter out = response.getWriter()) {
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/java56","root","");
            Statement st = con.createStatement();
            ResultSet res = st.executeQuery("select * from admin where username='"+request.getParameter("txtuser")+"' and password='"+request.getParameter("txtpass")+"'");
                 response.sendRedirect("index.jsp?q=invalid userid and password");
        catch(Exception ex)


Post a Comment


POST Answer of Questions and ASK to Doubt

Post a Comment (0)