Tutorial 2
In this tutorial, we will discuss how to create a Login.jsp and Register.jsp pages.
This tutorial, we discuss all the steps for creating a login.jsp and register.jsp page. Please first read the first tutorial of this project in the code section.
If you understand the first tutorial then you will understand the second tutorial. First, we create login.jsp and register.jsp and copy and paste this code into your Eclipse IDE. In the next tutorial, we discuss login.jsp and register.jsp and store registration record in the database. database connectivity.
Note:-Please read my first tutorial
1)Login.jsp
n<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ page import="java.sql.*,java.io.*" %> <%@ page import="javax.sql.*" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <% String uname = request.getParameter("user"); String pass = request.getParameter("pass"); // ResultSet resultSet = null; try{ Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/registration","ro ot","root"); String Query = "select * from register where Username=? and Password=?"; PreparedStatement st = con.prepareStatement(Query); st.setString(1,uname); st.setString(2,pass); ResultSet resultSet = st.executeQuery(); if(resultSet.next()){ out.println("username:"+uname); out.println("password:"+pass); } else{ response.sendRedirect("login.html"); } st.close(); con.close(); }catch(SQLException e){ e.printStackTrace(); } %> </body> </html>
2)Register.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %> <%@ page language="java" %> <%@ page session="true" %> <%@ page import="java.sql.*,java.io.*"%> <%@ page import ="javax.sql.*" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <% String FirstName = request.getParameter("fname"); String LastName = request.getParameter("lname"); String Username = request.getParameter("uname"); String Password = request.getParameter("pass"); String Email = request.getParameter("email"); String MobileNo = request.getParameter("mno"); String City = request.getParameter("ct"); try{ Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/registration","root","root"); ResultSet rs; String Query = "Insert into register(FirstName,LastName,Username,Password,Email,MobileNo,City)values(?,?,?,?,?,?,?)"; PreparedStatement st = con.prepareStatement(Query); st.setString(1, FirstName); st.setString(2, LastName); st.setString(3, Username); st.setString(4, Password); st.setString(5, Email); st.setString(6, MobileNo); st.setString(7, City); int result = st.executeUpdate(); out.println("User register Successfully"); System.out.println("Register Successfully"); st.close(); con.close(); }catch(SQLException e){ e.printStackTrace(); } %> </body> </html>
3)Table created in database:
My database name is:- registration
and my table name is:- register
Here is table:-

tq u sooo much it is most useful to me
I am very happy that your problem has been solved and thank you for visiting our blog.