Advanced Java Practical File Overview
Advanced Java Practical File Overview
CERTIFICATE
This is to certify that Miss SIDDHI A. NIVALE of S.Y [Link]. C.S. Semester IV
has completed the practical work in the Subject of Advanced Java during the
academic year 2021-22 under the guidance of Prof. Abhijeet Salvi being the
INDEX
Practical No: 1
[Link] file
import [Link].*;
import [Link].*;
import [Link].*;
public class Calculator extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
[Link]("text/html");
PrintWriter out = [Link]();
String n1 = [Link]("n1");
String n2 = [Link]("n2");
String op = [Link]("op");
switch (op) {
case "Addition":
[Link]("Answer = "+([Link](n1) + [Link](n2)));
break;
case "Subtraction":
[Link]("Answer = "+([Link](n1) - [Link](n2)));
break;
case "multiplication":
[Link]("Answer = "+([Link](n1) * [Link](n2)));
break;
default:
[Link]("Answer = "+([Link](n1) / [Link](n2)));
break;
}
}
}
:
Output:
b. Design a simple form using HTML which takes a number as an input & perform following
operations
i. Calculate Factorial
ii. Determine Prime Number or Not.
iii. Determine Number is Armstrong or Not.
Code :
<!DOCTYPE html>
<!--
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.
-->
<html>
<head>
<title>Practical 1A</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div><h1> PRACTICAL NO : 1 </h1></br>
<hr>
<h3>b.) Design a simple form using HTML which takes a number as an input & perform following operations</h3>
<p>
[Link] Factorial<br>
ii. Determine Prime Number or Not.<br>
iii. Determine Number is Armstrong or Not.
</p>
</div>
<div>
<form method="GET" action="prac_1A">
ENTER NUMBER : <input type="number" name="n">
<input type="submit" value="calculate">
</form>
</div>
</body>
</html>
prac_1A.java file
import [Link].*;
import [Link].*;
import [Link].*;
public class prac_1A extends HttpServlet{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException{
[Link]("text/html");
PrintWriter out=[Link]();
int n = [Link]([Link]("n"));
[Link]("<h2>The factorial of the given number "+ n + " is : </h2>");
int i=1,fact=1;
if(n==0)
{
[Link]("0");
}
else
{
while(i<=n)
{
fact=fact*i;
i=i+1;
}
[Link](fact);
}
[Link]("<br><h2>The given number is : " + n + "</h2>");
int flag=0;
for(i=2;i<=(n-1);i++)
{
if(n%2==0)
{
flag=1;
break;
}
}
if(flag==0)
{
[Link]("It is a Prime number");
}
else
{
[Link]("It is not a prime number,<br><br>");
}
[Link]("<h2>The given no. " + n + " is Armstrong or not ?</h2><br>");
int remainder, sum = 0, temp = 0;
temp = n;
while (n > 0) {
remainder = n % 10;
sum = sum + (remainder * remainder * remainder);
n = n / 10;
}
if (sum == temp) {
[Link]("It is a Armstrong number");
} else {
[Link]("It is Not a Armstrong number");
}
}
}
Output :
PRACTICAL-02
Aim:
a) Using Request Dispatcher Interface create a servlet
which will validate the password entered by the user, if the
user has entered “Servlet” as password, then he will be
forwarded to Welcome servlet else the user will stay on the
[Link] page and an error message will be displayed.
Code:
[Link]:
[Link]:
[Link]:
Output:
[Link]:
Output:
[Link]:
Output:
PRACTICAL NO : 3
Aim : a. Create a registration servlet in Java using JDBC. Accept the details such as
Username, Password, Email, and Country from the user using HTML Form and store the
registration details in the database.
b. Design database for student administration. Develop servlet(s) to perform CRUD
operations.
Index . Html
<!DOCTYPE html>
<html>
<head>
<title>Practical 3</title>
<meta charset="UTF-8">
<body>
</form>
</body>
</html>
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
try{
String username,password,email,country;
[Link]("psd"); email=
[Link]("email"); country=
[Link]("country");
[Link]("[Link]");
Connection con =
[Link]("jdbc:mysql://localhost:3306/user","root","")
;
[Link]("<h1>Connected</h1>");
[Link](1,username);
[Link](2,password); [Link](3,email);
[Link](4,country); [Link]();
Successfully</h3>");
}
catch(Exception e){ [Link](e);
Outout
b. Design database for student administration. Develop servlet(s)
to perform CRUD operations.
CODE
[Link]
<!DOCTYPE html>
<!--
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.
-->
<html>
<head>
<title>Student Administration</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
</head>
<body>
<center>
<h1>Student Administration</h1> <br><br>
<h2> <a href="[Link]">Add Stduent</a>
</h2><br>
<h2> <a href="viewStudent">View Stduent</a> </h2><br>
<h2> <a href="viewStudent">Update/Delete Stduent</a>
</h2><br>
</center>
</body>
</html>
[Link]
<!DOCTYPE html>
<html>
<head>
<title>Practical 3.B</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
</head>
<body>
<h1>Practical 3.B</h1> <br>
<form action="addStudent" method="post">
Roll : <input type='number' name='rollno'> <br><br>
First Name: <input type='text' name='fname'> <br><br>
Last Name : <input type='text' name='lname'> <br><br>
Age : <input type='number' name='age'> <br><br>
Course : <select name="course">
<br><br>
</form>
</body>
</html>
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
try{
String fname,lname,course;
int rollno=[Link]([Link]("rollno"));
fname= [Link]("fname"); lname=
[Link]("lname");
int age = [Link]([Link]("age"));
course= [Link]("course");
[Link]("[Link]");
Connection con =
[Link]("jdbc:mysql://localhost:3306/use
r","root","");
[Link]("<h1>Connected</h1>");
String query = "insert into studentdetails values(?,?,?,?,?)";
PreparedStatement ps = [Link](query);
[Link](1,rollno);
[Link](2,fname); [Link](3,lname);
[Link](4,age); [Link](5,course);
[Link](); [Link]();
[Link]("<h3>data Inserted
Successfully</h3>");
}
catch(Exception e){ [Link](e);
}
}
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
try{
[Link]("[Link]"); Connection
con =
[Link]("jdbc:mysql://localhost:3306/use
r","root","");
Statement st = [Link]();
String query= "select * from studentdetails order by roll_no";
[Link]("<center>");
[Link]("<h1>View Stdents</h1>");
[Link]("<table border='1'>"
+ "<thead>"
+ "<tr>"
+ "<td>Roll NO</td>"
+ "<td>First Name</td>"
+ "<td>Last Name</td>"
+ "<td>Age</td>"
+ "<td>Course</td>"
+ "<td>Update</td>"
+ "<td>Delete</td>"
+ "</thead>"
);
ResultSet rs = [Link](query); while([Link]()){
[Link]("<tr>"
+ "<td>"+[Link]("roll_no")+"</td>"
+ "<td>"+[Link]("firstName")+"</td>"
+ "<td>"+[Link]("lastName")+"</td>"
+ "<td>"+[Link]("age")+"</td>"
+ "<td>"+[Link]("course")+"</td>"
+ "<td>"+ "<a href='update?id=" + [Link]("roll_no")
+ "'> Edit </a>" +"</td>"
+ "<td>"+ "<a href='delete?id=" + [Link]("roll_no")
+ "'> Delete </a>" +"</td>"
+ "</form>"
);
}
}
catch(Exception e){ [Link](e);
}
}
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
int id = [Link]([Link]("id"));
try{
[Link]("[Link]");
Connection con =
[Link]("jdbc:mysql://localhost:3306/use
r","root","");
Statement st = [Link]();
String query= "select * from studentdetails where roll_no=?";
PreparedStatement ps = [Link](query);
[Link](1,id);
// [Link]("<h2>"+id+"</h2>"); [Link]("<h1>Update
Details</h1>");
while([Link]()){
[Link](""
+ "<form action='updatestudent' method='post'>\n" +
" Roll : <input type='number'
value='"+[Link]("roll_no")+"' name='rollno'> <br><br>" +
" First Name: <input type='text'
value='"+[Link]("firstName")+"' name='fname'> <br><br>"
+
" Last Name : <input type='text'
value='"+[Link]("lastName")+"' name='lname'> <br><br>\n"
+
" Age : <input type='number'
value='"+[Link]("age")+"' name='age'> <br><br>\n" +
" Course : <select name=\"course\">\n" +
" \n" +
}
catch(Exception e){
[Link](e);
}
}
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
int rollno=[Link]([Link]("rollno"));
Connection con =
[Link]("jdbc:mysql://localhost:3306/use
r","root","");
[Link]("<h1>Connected</h1>");
String query = "update studentdetails set
firstName=?,lastname=?, age=?,course=? where roll_no=?" ;
PreparedStatement ps = [Link](query);
[Link](1,fname);
[Link](2,lname); [Link](3,age);
[Link](4,course); [Link](5,rollno);
[Link]();
[Link]();
[Link]("<h3>data data updated Successfully</h3>");
}
catch(Exception e){
[Link](e);
}
}
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
int id = [Link]([Link]("id"));
try{
[Link]("[Link]");
Connection con =
[Link]("jdbc:mysql://localhost:3306/use
r","root",""); [Link]("<h1>Connected</h1>");
Statement st = [Link]();
String query= "delete from studentdetails where roll_no=?";
PreparedStatement ps = [Link](query);
[Link](1,id);
[Link]();
[Link]("data deleted successfully");
// RequestDispatcher rd=
[Link]("viewStudent");
// [Link](req, res);
}
catch(Exception e){
[Link](e);
}
}
Output :
Adding Details to database
Deleting data
Output:
[Link]
Practical 4
[Link].*; import
[Link].*; import
[Link].*;
[Link]("[Link]");
Connection con =
[Link]("jdbc:mysql://localhost:3306/user", "root", "");
Statement st = [Link]();
rs = [Link](query);
[Link](i));
[Link]("<br>");
} catch (Exception e) {
}
}
Output:
[Link]("[Link]");
Connection con =
[Link]("jdbc:mysql://localhost:3306/user",
"root", "");
[Link]("<br>Product Name" +
[Link]());
} catch (Exception e) {
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods.
Click on the + sign on the left to edit the code.">
Output :
PRACTICAL NO : 5
Aim : a. Develop a simple JSP application to display values obtained from the use
of intrinsic objects[Implicit Objects] of various types.
b. Develop a simple JSP application to pass values from one page to another with
validations. (Name-txt, age-txt, hobbies-checkbox, email-txt, gender-radio button)
a. Develop a simple JSP application to display values obtained from the use of
intrinsic objects[Implicit Objects] of various types // out object
<!DOCTYPE html>
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<%
// out object
[Link]("<br>Nu
m1 is " + num1);
[Link]("<br>Nu
m2 is " + num2);
%>
</body>
</html>
Output:
// request object
[Link]
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<br>
</form>
</body>
</html>
[Link]
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<%
age =[Link]([Link]("age"));
[Link]("Name : "+name);
[Link]("Age : "+age);
%>
</body>
</html>
Output :
// response
[Link]
<!DOCTYPE html>
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<%
[Link]("[Link]
%>
</body>
</html>
b. Develop a simple JSP application to pass values from one page to
another with validations. (Name-txt, age-txt, hobbies-checkbox, email-txt,
genderradio button)
[Link]
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<br>
<br>
Hobbies : <br>
<br>
<br>
</form>
</body>
</html>
[Link]
<!DOCTYPE html>
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<%
[Link]([Link]("age"));
{ [Link](str + ",");
%>
</body>
</html>
Output :
Practical no: 6
Code :
[Link]
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
</head>
<body>
<div class="signup-form">
<h1>Registration form</h1>
<div class="input-boxes">
<div class="input-box">
</div>
<div class="input-box">
<i class="fas fa-envelope"></i>
</div>
<div class="input-box">
</div>
<center>
</center>
</div>
</form>
</div>
</body>
</html>
[Link]
<%--
Document : Reg
Author : Siddhi
--%>
<%@page import="[Link].*"%>
<!DOCTYPE html>
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<%
String email;
email = [Link]("email");
try{
[Link]("[Link]");
Connection con =
[Link]("jdbc:mysql://localhost:3306/login","root","");
Statement st = [Link]();
PreparedStatement ps = [Link](query);
[Link](1,
Name);
[Link](2, email);
[Link](3, password);
[Link]();
[Link]();
}catch(Exception e)
{ [Link](e);
}
%>
</body>
</html>
[Link]
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
</head>
<body>
<div class="signup-form">
<h1>Login form</h1>
<div class="input-boxes">
<div class="input-box">
</div>
<div class="input-box">
</div>
<center>
</center>
</div>
</form>
</div>
</body>
</html>
[Link]
<%--
Document : Loginform
Author : Siddhi
--%>
<%@page import="[Link].*"%>
<!DOCTYPE html>
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<%
String email =
[Link]("email"); String
password; password =
[Link]("psw");
try{
[Link]("[Link]");
Connection con =
[Link]("jdbc:mysql://localhost:3306/login","root","");
Statement st = [Link]();
if([Link]()) {
}else{ o
[Link]("login Fails");
[Link]();
}catch(Exception e)
{ [Link](e);
%>
</body>
</html>
Output :
b. Create Employees table in EMP database. Perform select, insert,
update, and delete operations on the Employee table using JSP.
Code :
[Link]
<!DOCTYPE html>
<!--
-->
<html>
<head>
<title>Employee Administration</title>
<meta charset="UTF-8">
</head>
<body>
<center>
</center>
</body>
</html>
[Link]
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
</head>
<body>
<div class="signup-form">
<h1>Employee form</h1>
<div class="input-boxes">
<div class="input-box">
<option value="executive">Executive</option>
<option value="manager">Manager</option>
<option value="director">Director</option>
<option value="accountant">Accountant</option>
<option value="chief">Chief</option>
</select></div>
<div class="input-box">
<option value="female">Female</option>
<option value="male">Male</option>
</select></div>
</div>
</div>
</form>
</div>
</body>
</html>
[Link]
<%--
Document : addemp
Author : Siddhi
--%>
<%@page import="[Link].*"%>
<!DOCTYPE html>
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<%
int empid =
[Link]([Link]("empid")); String
[Link]([Link]("dob"));
[Link] job =
[Link]([Link]("sdate")); String
[Link]([Link]("bacc"));
[Link]([Link]("depid"));
try{
[Link]("[Link]");
Connection con =
[Link]("jdbc:mysql://localhost:3306/emp","root","");
Statement st = [Link]();
PreparedStatement ps = [Link](query);
[Link](1, empid);
[Link](2, ename);
[Link](3, dob);
[Link](4, job);
[Link](5, email);
[Link](6, sal);
[Link](7, bankac);
[Link](8, addr);
[Link](9, designation);
[Link](10, depid);
[Link](11, gender);
[Link]();
[Link]();
}catch(Exception e)
{ [Link](e);
%>
</body>
</html>
[Link]
<%--
Document : viewwmp
Author : Siddhi
--%>
<%@page import="[Link].*"%>
<!DOCTYPE html>
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<h1>Employee’s Detail</h1>
<thead>
<tr>
<th>Employee id</th>
<th>Name</th>
<th>D.O.B</th>
<th>Join date</th>
<th>Email id </th>
<th>Salary</th>
<th>Bank A/C</th>
<th>Address</th>
<th>Designation</th>
<th>Dept id</th>
<th>Gender</th>
<th colspan=\"4\">Action</th>
</tr>
</thead>
<%
try{
[Link]("[Link]");
Connection con =
[Link]("jdbc:mysql://localhost:3306/emp","root","");
Statement st = [Link]();
ResultSet rs = [Link](query);
while([Link]())
String email =
[Link]("email"); int
salary = [Link]("salary");
String designation =
[Link]("depid");
);
[Link]("</tbody></table><br><br>");
}catch(Exception e)
{ [Link](e);
%>
</body>
</html>
[Link]
<%--
Document : update
Author : Siddhi
--%>
<%@page import="[Link].*"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-
</head>
<body>
<div class="signup-form">
<%
try{
int id = [Link]([Link]("eid"));
[Link]("[Link]");
Connection con =
[Link]("jdbc:mysql://localhost:3306/emp","root","");
Statement st = [Link]();
//
PreparedStatement ps = [Link](query);
[Link](1, id);
ResultSet rs = [Link]();
<div class=\"input-boxes\">\n" +
"\n"+
"\n" +
" <div class=\"input-box\"><input type='text' value='"+[Link]("ename")+"'
name='name'></div>\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
" </select></div>\n" +
"\n" +
" </select></div>\n" +
" </div>\n" +
" </div>\n" +
" </form>");
catch(Exception e){
[Link](e);
%>
</div>
</body>
</html>
[Link]
<%--
Document : updateemp
Author : Siddhi
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="[Link].*"%>
<!DOCTYPE html>
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<%
try{
int empid =
[Link]([Link]("empid")); String
[Link]([Link]("dob"));
[Link] job =
[Link]([Link]("sdate")); String
= [Link]([Link]("bacc"));
int depid =
[Link]([Link]("depid"));
[Link]("[Link]");
Connection con =
[Link]("jdbc:mysql://localhost:3306/emp","root","");
String query = "update employ set eid=?,ename=?, dob=?,job=?,email=?,
salary=?,bankac=?,addr=?, designation=?,depid=?,gender=? where eid=?" ;
PreparedStatement ps = [Link](query);
[Link](1, empid);
[Link](2, ename);
[Link](3, dob);
[Link](4, job);
[Link](5, email);
[Link](6, sal);
[Link](7, bankac);
[Link](8, addr);
[Link](9, designation);
[Link](10, depid);
[Link](11, gender);
[Link](12, empid);
[Link]();
[Link]();
catch(Exception e){
[Link](e);
%>
</body>
</html>
[Link]
<%--
Document : Delete
Author : Siddhi
--%>
<%@page import="[Link].*"%>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<%
int id = [Link]([Link]("eid"));
try{
[Link]("[Link]");
Connection con =
[Link]("jdbc:mysql://localhost:3306/emp","root","");
Statement st = [Link]();
PreparedStatement ps = [Link](query);
[Link](1,id);
[Link]();
[Link]("<h3>data deleted
successfully</h3>");
catch(Exception e){
[Link](e);
%>
</body>
</html>
Output :