Skip to content
Ravi R. Oza

Ravi R. Oza

explore & share

  • Facebook
  • YouTube
  • Instagram
  • Twitter
  • LinkedIn
  • WordPress
  • Pinterest
  • GitHub
  • Home
  • Tutorial
    • C Language
      • Introduction to C Language (Chapter-1 Summary)
      • Understanding Control Structures in C Language (Chapter-2 Summary)
      • C Language Introduction
      • Algorithm and Flowchart in Programming
      • C Data Types
      • C Branching Statement
      • C Array
      • C Library Function
      • C User Defined Functions
      • Recursion In C
      • C Storage classes
      • C Structures
      • C Pointers
      • C Exercises
      • C Examples
      • C Language Question List for Exams
      • C – Old Question Papers
      • C Assignment
    • J2SE – Core Java
      • Paper Style
      • Question Bank
      • Java Examples
      • Java Assignment
    • J2EE – Advance Java
      • Java EE Architecture
      • JDBC Driver Types
      • JDBC Example
      • Servlet Tutorial
      • Question Bank
      • Differences
      • J2EE Assignment
    • Kotlin
      • Kotlin Introduction
      • Basic of Kotlin
      • Kotlin Decision Making
      • Kotlin Collections and Arrays
      • Functions in Kotlin
      • Kotlin Classes and Objects
      • Kotlin Inheritance
      • Kotlin Interface
      • Kotlin Examples
      • Kotlin Assignment
    • Android
      • Paper Style
      • Question Bank
    • BCA
    • PGDCA
  • Java in Gujarati
  • E-Books
  • Download
  • Leisure
    • આરાધના 🛕
    • Online Radio 📻 
  • About

login

Watch “Servlet Part-24 | Login and Logout using Http Session & JDBC (Gujarati)” on YouTube

September 1, 2020 by Ravi Oza
Servlet #SignUp #JDBC #MySql #Eclipse #MySqlWorkBench #ApacheTomcat #Jdk #Java #DynamicLogin #Gujarati #RaviROza #CreateReadUpdateAndDelete #CRUD #Create #read #update #delete #LogIn #LogOut #SignIn # SignOut

Steps to perform the example:

  1. Login
    1. Define HttpSession when user info. (id/password) is validated
    2. Add attributes to newly created session object
  2. Logout
    1. Define a servlet for user to Logout
    2. Retrieve current session object
    3. Remove attributes from session
    4. Call invalidate() method on session object

OS : Windows 10
Jdk : Version 8
IDE : Eclipse Mars
Database : MySQL using MySql Workbench 5.2 CE
Server : Apache Tomcat 7

follow me @
https://raviroza.wordpress.com/
https://twitter.com/raviozaIT
https://www.facebook.com/ravi.oza.it

Subscribe my channel to get latest video notification https://www.youtube.com/user/ravioza101

Share this:

  • WhatsApp
  • Post
  • Telegram

Like this:

Like Loading...
Categories Advance Java, BCA, Youtube Link Tags Apache Tomcat, CRUD, Eclipse, Java, JDBC, JDK, login, login with database, logout, Servlet, signin, signout, signup

Watch “Servlet Part-23 | New User Registration in Servlet using JDBC (Gujarati)” on YouTube

August 31, 2020 by Ravi Oza
#Servlet #SignUp #JDBC #MySql #Eclipse #MySqlWorkBench #ApacheTomcat #Jdk #Java #DynamicLogin #Gujarati #RaviROza

This video features the Sign up operation (New User registration) using JDBC via servlet only, no JSP page is used to perform any database operation.

MySql database is used as a back end support, the table tbl_users has been created using MySql Workbench in raviroza database.

Create the following files

NewUser.html (new user registration form – client side)

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>User Registration</title>
</head>
<body>
<form action="Signup" method="post">

<h1>New User Registration (Sign up)</h1>
<hr>
<p> Username : <input type="text" name="txtUsername"> </p>
<p> Password : <input type="password" name="txtPassword"> </p>
<hr>
<p> <input type="submit" value="Sign Up">
	<input type="reset" value="Reset">
 </p>
</form>
</body>
</html>

SignUp.java (servlet to add new user details in database if user doesn’t exist)

package dynamicLogin;

import java.io.IOException;
import java.io.PrintWriter;

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 java.sql.*;

@WebServlet("/Signup")
public class Signup extends HttpServlet 
{
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{	
		PrintWriter pw = response.getWriter();
		response.setContentType("text/html");
		
		Connection conn;
		PreparedStatement pst;
		String url,unam,pass,QRY="";
		
		url = "jdbc:mysql://localhost:3306/raviroza";
		unam = "root";
		pass = "ravi";
		
		try
		{
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection(url,unam,pass);
			String username = request.getParameter("txtUsername");
			String password = request.getParameter("txtPassword");
			QRY = "Select Username from tbl_users where Username=? and password=?";
			pst = conn.prepareStatement(QRY);
			pst.setString(1, username);
			pst.setString(2, password);
						
			if(pst.executeQuery().next())
			{
				pw.println("<h1>User Already Exist !!!</h1>");
			}
			else
			{
				QRY = "Insert into tbl_users values (?, ?)";
				pst = conn.prepareStatement(QRY);
				pst.setString(1, username);
				pst.setString(2, password);
				pst.executeUpdate();				
				pw.println("<h1>User Registration Done </h1>");
				pw.println("<p> <a href='index.html'>Login Here </a> </p>");
			}
			pw.close();
			pst.close();
			conn.close();
		}
		catch(Exception e)
		{
			pw.println("DB Error : "+e.toString());
		}
	}

}

Overall process of example:
When a new user select the “Sign Up” option from the registration page the request is sent to the SignUP Servlet, the servlet read the values of username and password from request. The new user registration module has been linked with Login module.

Servlet defines the Database connection with valid database connection information.

Prepared statement is used to check the username and password exists in users table. then, the same prepared statement is used to add new user information in database.

OS : Windows 10
Jdk : Version 8
IDE : Eclipse Mars
Database : MySQL using MySql Workbench 5.2 CE
Server : Apache Tomcat 7

follow me @
https://raviroza.wordpress.com/
https://twitter.com/raviozaIT
https://www.facebook.com/ravi.oza.it

Subscribe my channel to get latest video notification https://www.youtube.com/user/ravioza101

Share this:

  • WhatsApp
  • Post
  • Telegram

Like this:

Like Loading...
Categories Advance Java, BCA, Youtube Link Tags Apache Tomcat, CRUD, Eclipse, Java, JDBC, JDK, login, login with database, Servlet, signup

Watch “Servlet Part-22 | Dynamic Login in Servlet using JDBC” on YouTube

August 29, 2020 by Ravi Oza
Servlet #JDBC #MySql #Eclipse #MySqlWorkBench #ApacheTomcat #Jdk #Java #LoginApplication #DynamicLogin #Gujarati #RaviROza

This video features the Login operation using JDBC via servlet only, no JSP page is used to perform any database operation.

MySql database is used as a back end support, the table tbl_users has been created using MySql Workbench in raviroza database.

New Web Dynamic project has been used to define login application in eclipse.
Following are the resources used in project.

index.html (to read login information from client)

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Dynamic Login Application</title>
</head>
<body>
<form action="Login" method="post">

<h1>Welcome to Your Domain Login Page</h1>
<hr>
<p> Username : <input type="text" name="txtUsername"> </p>
<p> Password : <input type="password" name="txtPassword"> </p>
<hr>
<p> <input type="submit" value="Login">
	<input type="reset" value="Reset">
 </p>
</form>
</body>
</html>

Login.java (controller servlet to validate username and password )

package dynamicLogin;

import java.io.IOException;
import java.io.PrintWriter;

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 java.sql.*;

@WebServlet("/Login")
public class Login extends HttpServlet 
{
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		PrintWriter pw = response.getWriter();
		response.setContentType("text/html");
		
		Connection conn;
		PreparedStatement pst;
		String url,unam,pass,QRY="";
		
		url = "jdbc:mysql://localhost:3306/raviroza";
		unam = "root";
		pass = "ravi";
				
		try
		{
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection(url,unam,pass);
			String username = request.getParameter("txtUsername");
			String password = request.getParameter("txtPassword");
			QRY = "Select * from tbl_users where Username=? and password=?";
			pst = conn.prepareStatement(QRY);
			pst.setString(1, username);
			pst.setString(2, password);
			
			if(pst.executeQuery().next())
			{
				pw.println("<h1>Welcome User, "+username+ "</h1>");
				pw.println("<p> <a href='Logout'>Logout Here </a> </p>");
			}
			else
			{
				pw.println("<h1>Invalid login details </h1>");				
			}
		}
		catch(Exception e)
		{
			pw.println("DB Error : "+e.toString());
		}
	}
}

Overall process of example:
When a client/user select the “Submit” option from the clients page the request is sent to the Login Servlet, the servlet read the values of username and password from request.

Servlet defines the Database connection with valid database connection information.

Then, prepared statement is used to execute the queries. Here i have use used the prepared statement to check the username and password is exist in users table.

OS : Windows 10
Jdk : Version 8
IDE : Eclipse Mars
Database : MySQL using MySql Workbench 5.2 CE
Server : Apache Tomcat 7

follow me @
https://raviroza.wordpress.com/
https://twitter.com/raviozaIT
https://www.facebook.com/ravi.oza.it

Subscribe my channel to get latest video notification https://www.youtube.com/user/ravioza101

Share this:

  • WhatsApp
  • Post
  • Telegram

Like this:

Like Loading...
Categories Advance Java, BCA, Youtube Link Tags Apache Tomcat, CRUD, Eclipse, Java, JDBC, JDK, login, login with database, Servlet

Categories

  • Advance Java (93)
  • Android (11)
  • Android App (3)
  • Android example (3)
  • Answer Key (1)
  • BCA (56)
  • C Language (14)
  • Cloud Computing (2)
  • Exam (6)
  • Exam Paper (4)
  • Exam Schedule (1)
  • Exam Tips (1)
  • Games (1)
  • General (10)
  • Google Play Store (1)
  • Hibernate (1)
  • Hiring (1)
  • HJD (1)
  • Information (4)
  • Inspirational (8)
  • Java (4)
  • Java Example (1)
  • JDBC (12)
  • Jobs (2)
  • JSP (3)
  • Kotlin (8)
  • Message (9)
  • Microsoft (1)
  • News (2)
  • Personal (3)
  • PGDCA (1)
  • Poll (1)
  • Question Paper (3)
  • Saurashtra University (5)
  • Servlet (5)
  • Smarphone (2)
  • Spring (5)
  • Struts Framework (2)
  • TCS (5)
  • Tech News (1)
  • Technology (7)
  • Tips (7)
  • Uncategorized (6)
  • Webinar (3)
  • Windows Tips (2)
  • Youtube Link (83)

Archives

  • February 2024 (1)
  • November 2023 (2)
  • October 2023 (1)
  • April 2023 (2)
  • March 2023 (3)
  • February 2023 (2)
  • January 2023 (4)
  • December 2022 (1)
  • October 2022 (1)
  • July 2022 (2)
  • May 2022 (1)
  • April 2022 (2)
  • March 2022 (2)
  • February 2022 (3)
  • January 2022 (6)
  • December 2021 (4)
  • October 2021 (7)
  • August 2021 (5)
  • July 2021 (8)
  • May 2021 (1)
  • April 2021 (1)
  • March 2021 (1)
  • October 2020 (21)
  • September 2020 (20)
  • August 2020 (22)
  • July 2020 (7)
  • September 2019 (5)
  • March 2019 (3)
  • September 2018 (2)
  • August 2018 (6)
  • July 2018 (7)
  • May 2018 (2)
  • February 2018 (1)
  • November 2017 (1)
  • October 2017 (1)
  • September 2017 (10)
  • August 2017 (8)
  • March 2017 (3)
  • February 2017 (3)
  • December 2012 (3)

Recent Posts

  • Animation in Android/Kotlin
  • TCS BSc BCA (Smart Hiring) – 2023 & 2024 batch – Registrations open !
  • C Language Answer key (Nov-2023)
  • BCA semester 1 (WEF-2023)
  • Power Apps | Automatically App creation with Copilot or from scratch

Tags

android (9) Apache Tomcat (24) bca (7) Bean (4) Controller (6) CRUD (7) DAO (4) database schema (4) Eclipse (41) get:property (4) Hibernate (6) Hibernate Framework (6) in (4) Java (49) JavaServerPages (17) JDBC (18) JDK (35) JSP (19) kotlin (6) Model View Controller (6) MVC (6) mvc example (5) mvc example in java (5) mvc in jsp with example (5) mysql (6) saurashtra university (6) Servlet (25) Session Management (6) Spring Framework (5) View (6)

Video tutorial to learn C language
Video tutorial to learn Java (core Java)
Video tutorial to learn JDBC
May 2025
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Feb    
© 2025 Ravi R. Oza • Built with GeneratePress
%d