Watch “Servlet Part-9 (Enumeration to Read Headers and Parameters)” on YouTube

A request object of servlet consist the client information , such as client header information and client input parameters.
Here, Enumeration is used to read the values of client headers (list of headers) and to read the values of parameters (list of input parameters).

OS : Windows 10
Jdk : Version 8
IDE : Eclipse Mars
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

Watch “Servlet Part-8 (Servlet Context and Servlet Config parameter)” on YouTube

Servlet Context parameters are application wide parameter (such as global variables) accessible through out web application, any servlet or Jsp page can access these parameters, and there is only one copy of such parameters per web app.

These parameters are to be configured in web.xml file in java web application.

Servlet config parameters are specific to the servlet for which is declared, it is local for that servlet. These parameters are private to each servlet. These parameters are also configured in web.xml (inside servlet tag).

OS : Windows 10
Jdk : Version 8
IDE : Eclipse Mars
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

Servlet Part-7 (Servlet Mapping with Deployment Descriptor/web.xml file)

Deployment descriptor file which is also known as web.xml file, is used to configure the web app as well as servlet.

It is most important while the web app is to be deployed on the server, for example the database connection is going to differ while you deploy the app on server, so its preferable to define such settings in web.xml file because its a tag file which can be easily editable in any editor.

If we define the such settings in java file they need to be edited and re-compile on server, which is not feasible.

OS : Windows 10
Jdk : Version 8
IDE : Eclipse Mars
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

Watch “Servlet Part-6 (Arithmetic Operations Example using Servlet)” on YouTube

Arithmetic Operations of two numbers using Servlet.

  • index.html (client side : user interface to accept the input from user)
  • airth.java (server side : servlet to process request made by user to perform arithmetic operation on two number)

OS : Windows 10
Jdk : Version 8
IDE : Eclipse Mars
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

Watch “Servlet Part-4 (Servlet Life Cycle Example)” on YouTube

Servlet Interface provides general activities for servlet.

It resides in javax.servlet.Servlet, when implementing Servlet following five method must be implemented (init, service, destroy, getServletConfig & getServletInfo).

OS : Windows 10
Jdk : Version 8
IDE : Eclipse Mars
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

Watch “Servlet Part-3 (Generic Servlet Example)” on YouTube

Practical Implementation of Servlet using GenericServlet Class

Step to Create Servlet using GenericServlet Class

  1. Apache Tomcat configuration in Eclipse for web projects
  2. Creating Dynamic web project
  3. Add java class that extends the GenericServlet class (in new class wizard)

OS : Windows 10
Jdk : Version 8
IDE : Eclipse Mars
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

Watch “Servlet Part-2 (Implementation)” on YouTube

This video contains the following

  • Servlet Architecture
  • Packages of Servlet
  • Generic Servlet
  • Http Servlet
  • HTTP Response-Request Model
  • Tomcat Container
  • Servlet Implementation

OS : Windows 10
Jdk : Version 8
IDE : Eclipse Mars
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

Watch “Servlet Part-1 | Introduction to Servlet, CGI & Advantages of Servlet (Gujarati)” on YouTube

  • Servlet Definition and functionality
  • Introduction to CGI (before Servlet)
  • Limitation of CGI
  • Advantages of Servlet

OS : Windows 10
Jdk : Version 8
IDE : Eclipse Mars
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

JDBC : Menu Driven Application

Menu Driven application in Java to use various JDBC operation. In this example DB operation is managed by a class called “clsDB.java”, the Student data is managed by a class called “Student.java”. The “Main.java” file consist of Main function as well as menu to perform various operation related to student.

To connect with MySQL database, one need the valid driver and URL string. Below is the user defined class that connect with the MySQL database and also manages the other operation such as related to it.

Below is the list of methods that handles various database operation.

  • Execute SQL
  • Defines and returns the Result set related to a query
  • Add, Update, Delete and Display the “Student” class details
Field NameData type, sizeConstraint
Snoint (3)Primary Key
Snametext(30)
Student Table in RRO database (MySQL)
create table stud (sno int(3) primary key, sname text(30))

clsDB.java

import java.sql.*;

// Developed by Ravi R. Oza
// Jamnagar, Gujarat
// raviroza.wordpress.com
public class clsDB {
	Connection cn;
	Statement st;
	String url = "jdbc:mysql://localhost:3306/rro", username = "root", password = "";

	public clsDB() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			cn = DriverManager.getConnection(url, username, password);
		} catch (Exception err) {
			System.out.println("Error : " + err);
		}
	}

	public void myExecuteQry(String s) {
		try {
			st = cn.createStatement();
			st.executeUpdate(s);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public ResultSet getResultSet(String s) {
		ResultSet r;
		try {
			st = cn.createStatement();
			r = st.executeQuery(s);
			return r;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	public void addStudent(Student stud) {
		String q = "insert into stud (sno,sname) values (" + stud.getSno() + ",'" + stud.getSname() + "')";
		myExecuteQry(q);
	}

	public void updateStudent(Student stud) {
		String q = "update stud set sname = '" + stud.getSname() + "' where sno = " + stud.getSno() + "";
		myExecuteQry(q);
	}

	public void deleteStudent(Student stud) {
		String q = "delete from stud where sno = " + stud.getSno() + "";
		myExecuteQry(q);
	}

	public void displayStudent() throws SQLException {
		ResultSet r = getResultSet("Select * from stud");
		System.out.println("No.\t\t\tName");
		while (r.next()) {
			System.out.print(r.getInt(1) + "\t\t\t" + r.getString(2) + "\n");
		}
	}
}

Student.java

import java.util.Scanner;

public class Student 
{
	private int sno;
	private String sname;	
	Scanner sc = new Scanner(System.in);
	
	public void readSno()
	{
		System.out.print("Enter stud no : ");  
		sno = sc.nextInt();
	}
	public void readSname()
	{
		System.out.print("Enter stud name : ");  
		sname = sc.next();
	}
	
	
	public int getSno() {
		return sno;
	}
	public void setSno(int sno) {
		this.sno = sno;
	}
	public String getSname() {
		return sname;
	}
	public void setSname(String sname) {
		this.sname = sname;
	}
	
}

Main.java

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Scanner;

public class Main
{
	
	public static void main(String[] args) throws SQLException
	{
		Scanner sc = new Scanner(System.in);
		clsDB db = new clsDB();
		
		int ch=0;
		Student stud = new Student();
		
		while(ch!=5)
		{		
			System.out.println("Main Menu for Student Data Entry");
			System.out.println("1. Add student details");
			System.out.println("2. Update student details");
			System.out.println("3. Delete student details");
			System.out.println("4. Display all the student details");
			
			System.out.println("5. Exit");

			System.out.print("Enter your choice : ");
			ch = sc.nextInt();
			
			if(ch == 1)
			{
				System.out.println("Adding student details");
				System.out.print("Enter stud no : ");  
					stud.setSno(sc.nextInt());
				System.out.print("Enter stud name : ");
					stud.setSname(sc.next());
					
				db.myExecuteQry("insert into stud (sno,sname) values ("+stud.getSno()+",'"+stud.getSname()+"')");
				System.out.println("Record added successfully...");				
			}
			else if(ch == 2)
			{
				System.out.println("Updating student details");
				System.out.print("Enter stud no to be updated : ");
				stud.setSno(sc.nextInt());
				System.out.print("Enter new name for student : ");
				stud.setSname(sc.next());
				db.myExecuteQry("update stud set sname = '"+stud.getSname()+"' where sno = "+stud.getSno()+"");
				System.out.println("Record updated successfully...");				
			}
			else if(ch == 3)
			{
				System.out.println("Deleting student details");
				System.out.print("Enter stud no to be deleted : ");
				stud.setSno(sc.nextInt());				
				db.myExecuteQry("delete from stud where sno = "+stud.getSno()+"");
				System.out.println("Record deleted successfully...");				
			}
			else if(ch == 4)
			{
				System.out.println("Displaying student details");
				ResultSet r = db.getResultSet("Select * from stud");
				System.out.println("No.\t\t\tName");
				while(r.next())
				{
					System.out.print(r.getInt(1)+"\t\t\t"+r.getString(2)+"\n");
				}
			}
			else if(ch==5)
			{
				System.exit(0);
			}			
		}		
	}
}

JDBCUsingPOJO.java

import java.sql.SQLException;
import java.util.Scanner;

public class JDBCUsingPOJO 
{	
	public static void main(String[] args) throws SQLException
	{
		Scanner sc = new Scanner(System.in);
		int ch=0;
		clsDB 	db 		= new clsDB();			
		Student stud 	= new Student();
		
		while(ch!=5)
		{		
			System.out.println("Main Menu for Student Data Entry");
			System.out.println("1. Add student details");
			System.out.println("2. Update student details");
			System.out.println("3. Delete student details");
			System.out.println("4. Display all the student details");
			
			System.out.println("5. Exit");

			System.out.print("Enter your choice : ");
			ch = sc.nextInt();
			
			if(ch == 1)
			{				
				System.out.println("adding student : ");
				stud.readSno();
				stud.readSname();
				db.addStudent(stud);
				System.out.println("Record added successfully...");				
			}
			else if(ch == 2)
			{				
				System.out.println("updating student : ");
				stud.readSno();
				stud.readSname();				
				db.updateStudent(stud);
				System.out.println("Record updated successfully...");				
			}
			else if(ch == 3)
			{				
				System.out.print("Deleting  student: ");
				stud.readSno();				
				db.deleteStudent(stud);
				System.out.println("Record deleted successfully...");				
			}
			else if(ch == 4)
			{
				System.out.println("Displaying student details");
				db.displayStudent();
			}
			else if(ch==5)
			{
				System.exit(0);
			}			
		}		
	}
}