Login and Registration for JSP



admin.jsp

<%@include  file="header.jsp" %>

<section>
    <center>
    <h1>Admin Login Here</h1>
    <form action="AdminSer" method="post">
        <input type="text" name="txtuser" placeholder="Enter username" />
        <br><br>
        <input type="password" name="txtpass" placeholder="Enter password" />
        <br><br>
        <input type="submit" name="btnsubmit" value="Login"/>
     
    </form>
    </center>
 
</section>


<%@include file="footer.jsp" %>



AdminSer

/*
 * 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.
 */
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Hp
 */
public class AdminSer extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            PrintWriter out = response.getWriter();
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/stuinfo","root","");
            Statement st = con.createStatement();
            ResultSet x = st.executeQuery("select * from tbl_admin where username='"+request.getParameter("txtuser")+"' and password='"+request.getParameter("txtpass")+"'");
            if(x.next())
            {
              response.sendRedirect("StudentInfo.jsp");
            }
            else
            {
                out.print("invalid userid and password");
            }
         
        } catch (Exception ex) {
       
        }
    }

}



Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post