Program-1
Filename : [Link]
import [Link].*;
import [Link].*;
public class WelcomeServlet extends GenericServlet
{
public void service(ServletRequest request,ServletResponse response)
throws ServletException,IOException
{
[Link]("text/html");
PrintWriter pw=[Link]();
[Link]("<h1>Welcome to Servlet</h1>");
[Link]();
}
}
Output:
Program-2
Filename : Purchase_order_form.html
<html>
<head>
<title>PurchaseOrderForms</title>
</head>
<body>
<h2>Purchase Order Forms</h2>
<form name="Purchase_order_form"action="ProcessPurchaseOrderServlet"
method="post">
<label for="cust_name">Customer Name:</label>
<input type="text"id="cust_name"name="cust_name"required><br>
<label for="place">Place:</label>
<input type="text"id="place"name="place"required><br>
<label for="contact_number">Contact Number:</label>
<input type="number"id="contact_number"name="contact_number"
required><br>
<label for="date">Date:</label>
<input type="text"id="date"name="date"required><br>
<label for="product_name">Product Name:</label>
<input type="text"id="product_name"name="product_name"required><br>
<label for="quantity">Quantity:</label>
<input type="number"id="quantity"name="quantity"required><br>
<label for="unit_price">Unit Price:</label>
<input type="text"id="unit_price"name="unit_price"required><br>
<button type="submit">Submit Purchase List</button>
</form>
</body>
</html>
Filename:[Link]
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
import [Link];
import [Link];
public class ProcessPurchaseOrderServlet extends HttpServlet
{
private static final long serialVersionUID=1L;
protected void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
String productName=[Link]("product_name");
int quantity=[Link]([Link]("quantity"));
double unitprice=[Link]([Link]("unit_price"));
String custname=[Link]("cust_name");
long contactnumber=[Link]([Link]
("contact_number"));
String place=[Link]("place");
String date=[Link]("date");
double totalCost=quantity * unitprice;
[Link]("text/html");
PrintWriter out=[Link]();
[Link]("<html><body>");
[Link]("<h1>      
         
XYZ Companies  </h1>");
[Link]("<h2>        
         
Purchase Order Summary  </h1>");
[Link]("<table style=width:700px>");
[Link]("<tr><th>Customer Name:"+custname+"</th><th>Distributer
code:DC001</th></tr>");
[Link]("<tr><th>Customer Place:"+place+"</th><th>Purchase Order
code:PC001</th></tr>");
[Link]("<tr><th>Contact
Number:"+contactnumber+"</th><th>Date:"+date+"</th></tr>");
[Link]("</table>");
[Link]("<table border=1 bgcolor=lightblue style=width:700px>");
[Link]("<tr><th>ProductName</th><th>Quantity</th><th>UnitPrice</th><th>TotalC
ost</th></tr>");
[Link]("<tr><th>"+productName+"</th><th>"+quantity+"</th><th>"+unitprice+"</th
><th>"+totalCost+"</th></tr>");
[Link]("</table>");
[Link]("</body></html>");
}
}
Output:
Program-3
Filename:[Link]
<html>
<head>
<title>To do supply a title</title>
</head>
<body>
<center>
<h1>Student marks</h1>
<form action="[Link]"method="get">
<table border="1">
<tr>
<td>Mark 1</td>
<td><input type="text"name="m1"/>
</td>
</tr>
<tr>
<td>Mark 2</td>
<td><input type="text"name="m2"/>
</td>
</tr>
<tr>
<td>Mark 3</td>
<td><input type="text"name="m3"/>
</td>
</tr>
<tr><td colspan="2">
<input type="submit"value="submit"name="submit"/>
</td>
</tr>
</table>
</center>
</body>
</html>
Filename:[Link]
<html>
<body>
<%
int mark1=[Link]([Link]("m1"));
int mark2=[Link]([Link]("m2"));
int mark3=[Link]([Link]("m3"));
if(mark1>=50&&mark2>=50&&mark3>=50)
{
[Link]("You are pass</br>");
int tot=mark1+mark2+mark3;
int per=tot/3;
[Link]("Your total mark is :"+tot+"<br>");
[Link]("Percentage is:"+per);
}
else
{
[Link]("You are fail");
}
%>
</body>
</html>
Output:
Program-4
Filename:[Link]
<html>
<head>
<title>PurchaseOrderForms</title>
</head>
<body>
<h2>Purchase Order Forms</h2>
<form name="process"action="[Link]"method="post">
<label for="cust_name">Customer Name:</label>
<input type="text"id="cust_name"name="cust_name"required><br>
<label for="place">Place:</label>
<input type="text"id="place"name="place"required><br>
<label for="contact_number">Contact Number:</label>
<input type="number"id="contact_number"name="contact_number
required><br>
<label for="date">Date:</label>
<input type="text"id="date"name="date"required><br>
<label for="product_name">Product Name:</label>
<input type="text"id="product_name"name="product_name" required>
br>
<label for="quantity">Quantity:</label>
<input type="number"id="quantity"name="quantity"required><br>
<label for="unit_price">Unit Price:</label>
<input type="text"id="unit_price"name="unit_price"required><br>
<button type="submit">Submit Purchase List</button>
</form>
</body>
</html>
Filename:[Link]
<html>
<body>
<%
String productName=[Link]("product_name");
int quantity=[Link]([Link]("quantity"));
double unitprice=[Link]([Link]("unit_price"));
String custname=[Link]("cust_name");
long contactnumber=[Link]([Link]
("contact_number"));
String place=[Link]("place");
String date=[Link]("date");
double totalCost=quantity * unitprice;
[Link]("<html><body>";
[Link]("<h1>          
     XYZ Companies  </h1>");
[Link]("<h2>          
       Purchase Order Summary
 </h1>");
[Link]("<table style=width:700px>");
[Link]("<tr><th>Customer Name:"+custname+"</th><th>Distributer
code:DC001</th></tr>");
[Link]("<tr><th>Customer Place:"+place+"</th><th>Purchase Order
code:PC001</th></tr>");
[Link]("<tr><th>Contact
Number:"+contactnumber+"</th><th>Date:"+date+"</th></tr>");
[Link]("</table>");
[Link]("<table border=1 bgcolor=lightblue style=width:700px>");
[Link]("<tr><th>ProductName</th><th>Quantity</th><th>UnitPrice</th><th>TotalC
ost</th></tr>");
[Link]("<tr><th>"+productName+"</th><th>"+quantity+"</th><th>"+unitprice+"</th
><th>"+totalCost+"</th></tr>");
[Link]("</table>");
[Link]("</body></html>");
%>
</body>
</html>
Output:
Program-5
Filename:[Link]
<html>
<head>
<title>Employee pay slip</title>
</head>
<body>
<h2>Enter the following details:</h2>
<form action="[Link]"method="post">
<table border="1">
<tr><td>Enter employee name:</td>
<td><input type="text"name="name"></td></tr>
<tr><td>Enter employee Id:</td>
<td><input type="text"name="id"></td></tr>
<tr><td>Enter designation:</td>
<td><input type="text"name="ds"></td></tr>
<tr><td>Enter payment date:</td>
<td><input type="date"name="pd"></td></tr>
<tr><td>Enter basic salary:</td>
<td><input type="number"name="bs"></td></tr>
<tr>
<td colspan="2">
<input type="submit"value="submit"name="submit"></td></tr>
</table>
</form>
</body>
</html>
Filename:[Link]
<html>
<body>
<%
String name=[Link]("name");
int id=[Link]([Link]("id"));
double bs=[Link]([Link]("bs"));
String designation=[Link]("ds");
String date=[Link]("pd");
double da=bs*0.3;
double ta=bs*0.3;
double hra=bs*0.3;
double ma=bs * 0.4;
double others=bs*0.03;
double allowances = da+ta+hra+ma+others;
double insurance= bs*0.03;
double epf=bs*0.1;
double tax=bs*0.01;
double deductions=insurance+epf+tax;
double gs=bs+allowances;
double netSalary= gs-deductions;
[Link]("<html> <body bgcolor=lightblue>");
[Link]("<center><h1> KL Companies </h1></center>");
[Link]("<center><h2> Pay Slip for March 2024 </h2></center>");
[Link]("<center>Employee id : "+id+"</center><br>");
[Link]("<center>Designation : "+designation+"</center><br>");
[Link]("<center>Payment Date : "+date+"</center><br>");
[Link]("<center> <table border=1>");
[Link]("<tr> <th colspan=2> Earnings</th><th
colspan=2>Deductions</th></tr>");
[Link]("<tr> <td>Basic Salary</td><td> "+bs+" </td><td>Insurance</td><td>
"+insurance+"</td></tr>");
[Link]("<tr><td>Dearness Allowances</td><td> "+da+" </td><td>EPF</td><td>
"+epf+"</td></tr>");
[Link]("<tr><td>Travelling Allowances</td><td> "+ta+"
</td><td>Tax</td><td>"+tax+"</td></tr>");
[Link]("<tr><td>Home resent Allowance</td><td> "+hra+"</td><td
colspan=2></td></tr>");
[Link]("<tr><td>Medical Allowance</td><td> "+ma+"</td><td
colspan=2></td></tr>");
[Link]("<tr><td>Other Allowance</td><td> "+others+"</td><td
colspan=2></td></tr>");
[Link]("<tr><td>Gross salary</td><td> "+gs+"</td><td>Total
Deductions</td><td>"+deductions+"</td></tr>");
[Link]("<tr><td colspan=3>Net salary</td><td> "+netSalary+"</td></tr>");
[Link]("</table></center>");
[Link]("</body></html>");
%>
</body>
</html>
Output:
Program:6
Filename : [Link]
import [Link].*;
import [Link].*;
public class JdbcExample
{
Connection connection;
public JdbcExample()
{
try
{
[Link]("[Link]");
connection=[Link]("jdbc:odbc:userdetails1","","");
[Link]("Connected to the database");
}
catch(Exception e)
{
[Link]([Link]());
}
}
public void createTable()
{
String sql="CREATE TABLE users("+"id AUTOINCREMENT PRIMARY KEY,"+"name
VARCHAR(100),"+"email VARCHAR(100)"+")";
try
{
Statement stmt=[Link]();
[Link](sql);
[Link]("Table created Successfully");
}
catch (SQLException e)
{
[Link]();
}
}
public void insertRecord(String name,String email)
{
String sql="INSERT INTO users (name,email)values(?,?)";
try
{
PreparedStatement pstmt=[Link](sql);
[Link](1,name);
[Link](2,email);
[Link]();
[Link]("Record inserted Successfully.");
}
catch(SQLException e)
{
[Link]();
}
}
public void deleteRecord(int id)
{
String sql="DELETE FROM users WHERE id=?";
try
{
PreparedStatement pstmt=[Link](sql);
[Link](1,id);
[Link]();
[Link]("Record deleted Successfully.");
}
catch(SQLException e)
{
[Link]();
}
}
public void listRecords()
{
String sql="SELECT * FROM users";
try
{
Statement stmt=[Link]();
ResultSet rs=[Link](sql);
[Link]("Listing Records:");
while([Link]())
{
int id=[Link]("id");
String name=[Link]("name");
String email=[Link]("email");
[Link]("ID:"+id+",Name:"+name+",Email:"+email);
}
}
catch(SQLException e)
{
[Link]();
}
}
public static void main(String[]args)
{
JdbcExample jdbcExample=new JdbcExample();
[Link]();
[Link]("John","john@[Link]");
[Link]("Smith","smith@[Link]");
[Link]("Rosy","rosy@[Link]");
[Link]();
[Link](1);
[Link]();
}
}
Output:
Connected to the database
Table created Successfully.
Record inserted Successfully.
Record inserted Successfully.
Record inserted Successfully.
Listing Records:
ID:1,Name:John,Email:john@[Link]
ID:2,Name:Smith,Email:smith@[Link]
ID:3,Name:Rosy,Email:rosy@[Link]
Record deleted Successfully.
Listing Records:
ID:2,Name:Smith,Email:smith@[Link]
ID:3,Name:Rosy,Email:rosy@[Link]
BUILD SUCCESSFUL (total time: 0 seconds)
Program-7
Filename: [Link]
<html>
<head>
<title>Welcome</title>
</head>
<body>
<h1>Welcome to servlet programming</h1>
<form method="get"action="myaddress">
<p>Please provide the following details</p>
<p>Name:<input type="text"name="name"></p>
<p>Place:<input type="text"name="place"></p>
<p>District:<input type="text"name="district"></p>
<p>State:<input type="text"name="state"></p>
<p>Pincode:<input type="text"name="pin"></p>
<input type="Submit"value="submit">
</form>
</body>
</html>
Filename:[Link]
import [Link].*;
import [Link].*;
import [Link].*;
public class myaddress extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws
IOException
{
[Link]("text/html");
PrintWriter out=[Link]();
String name=[Link]("name");
String place=[Link]("place");
String state=[Link]("state");
String district=[Link]("district");
String pin=[Link]("pin");
[Link]("<html>");
[Link]("<head><title>"+name+"Responses</title></head>");
[Link]("<body>");
[Link]("<h1>Welcome "+name+"</h1>");
[Link]("<h2>You are from "+ place+".<br>");
[Link]("Which is "+ district +" district of ");
[Link](state+" state ");
int pincode=[Link](pin);
[Link](" with "+pincode+" pincode in Indian.<br> Great to meet you</h2>");
[Link]("</body>");
[Link]("</html>");
}
}
Output:
Program-8
Filename : [Link]
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
public class ShowRequestHeaders1 extends HttpServlet
{
public void doGet(HttpServletRequest request , HttpServletResponse response)
throws ServletException , IOException
{
[Link]("text/html");
PrintWriter out=[Link]();
String title= "Http Header Request Example";
String docType= "<!docType html public\"//w3c//dtd html
4.0"+"transactional//en\" > \n ";
[Link](docType + "<html>\n "+" <head><title> "+title+"
</title></head>\n "+" <body bgcolor=\"F0F0F0\">\n "+" <h1 align=\"center\"> "+title+"
</h1>\n "+" <table width=\"100%\" border=\"1\" align=\"center\">\n "+" <tr
bgcolor=\"#949494\">\n "+" <th>Header Name</th><th> Header value(s)</th>\n "+"
</tr>\n");
Enumeration headerNames=[Link]();
while([Link]())
{
String paramName=(String)[Link]();
[Link]("<tr><td> "+paramName+" </td>\n");
String paramValue=[Link](paramName);
[Link]("<td> "+paramValue+" </td></tr> \n");
}
[Link]("</table>\n </body></html>");
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException , IOException
{
doGet(request,response);
}
}
Output:
Program-9
Filename : [Link]
<html>
<head>
<title></title>
</head>
<body>
<form action ="[Link]">
<input type="text" name="uname">
<input type="submit" value="go"><br>
</form>
</body>
</html>
Filename : [Link]
<html>
<body>
<h1>
Display the session value on this page
</h1>
<%
String name=(String)[Link]("user");
[Link](" Hello " + name);
%>
</body>
</html>
Filename : [Link]
<html>
<body>
<%
String name=[Link]("uname");
[Link]("Welcome " + name);
[Link]("user",name);
%>
<a href="[Link]"> Display the value </a>
</body>
</html>
Output:
Program – 10
Filename : [Link]
import [Link];
import [Link];
public class Client
{
private Client(){}
public static void main(String[] args)
{
try
{
Registry registry=[Link](null);
Hello stub=(Hello)[Link]("Hello");
[Link]();
}
catch(Exception e)
{
[Link]("Client Exception:" + [Link]());
[Link]();
}
}
}
Filename : [Link]
import [Link];
import [Link];
import [Link];
import [Link];
public class Server extends ImplExample
{
public Server(){}
public static void main(String[] args)
{
try
{
ImplExample obj=new ImplExample();
Hello stub=(Hello) [Link](obj,0);
Registry registry=[Link]();
[Link]("Hello",stub);
[Link]("Server ready");
}
catch(Exception e)
{
[Link]("server Exception:"+[Link]());
[Link]();
}
}
}
Filename : [Link]
import [Link];
import [Link];
interface Hello extends Remote
{
void printMsg() throws RemoteException;
}
public class ImplExample implements Hello
{
public void printMsg()
{
[Link]("This is an example RMI program");
}
}
Output:
Server:
Microsoft Windows [Version 10.0.22000.2538]
(c) Microsoft Corporation. All rights reserved.
C:\Users\User>d:
D:\>cd New folder (5)\726
D:\New folder (5)\726>cd rmi
D:\New folder (5)\726\rmi>set path="C:\Program Files (x86)\Java\jdk1.6.0\bin"
D:\New folder (5)\726\rmi>javac *.java
D:\New folder (5)\726\rmi>start rmiregistry
D:\New folder (5)\726\rmi>java Server
Server ready
This is an example RMI program
Client:
Microsoft Windows [Version 10.0.22000.2538]
(c) Microsoft Corporation. All rights reserved.
C:\Users\User>D:
D:\>cd New folder (5)\726
D:\New folder (5)\726>cd rmi
D:\New folder (5)\726\rmi>set path="C:\Program Files (x86)\Java\jdk1.6.0\bin"
D:\New folder (5)\726\rmi>java Client
D:\New folder (5)\726\rmi>
Program – 11
Filename : [Link]
import [Link].*;
import [Link].*;
import [Link].*;
/*<applet code="Calculator" width=600 height=600>
</applet>*/
public class Calculator extends Applet implements ActionListener
{
TextField inp;
public void init()
{
setBackground([Link]);
setLayout(null);
int i;
inp=new TextField();
[Link](150,100,270,50);
[Link](inp);
Button button[]=new Button [10];
for(i=0;i<10;i++)
{
button[i]=new Button([Link](9-i));
button[i].setBounds(150+((i%3)*50),150+((i/3)*50),50,50);
[Link](button[i]);
button[i].addActionListener(this);
}
Button dec=new Button(".");
[Link](200,300,50,50);
[Link](dec);
[Link](this);
Button clr=new Button("C");
[Link](250,300,50,50);
[Link](clr);
[Link](this);
Button op[]=new Button[5];
op[0]=new Button ("/");
op[1]=new Button ("*");
op[2]=new Button ("-");
op[3]=new Button ("+");
op[4]=new Button ("=");
for(i=0;i<4;i++)
{
op[i].setBounds(300,150+(i*50),50,50);
[Link](op[i]);
op[i].addActionListener(this);
}
op[4].setBounds(350,100,70,250);
[Link](op[4]);
op[4].addActionListener(this);
}
String nu1="";
String op="";
String nu2="";
public void actionPerformed(ActionEvent e)
{
String button =[Link]();
char ch=[Link](0);
if(ch>='0' && ch<='9'||ch=='.')
{
if ()
nu2=nu2+button;
else
nu1=nu1+button;
[Link](nu1+op+nu2);
}
else if(ch=='C')
{
nu1=op=nu2="";
[Link]("");
}
else if (ch=='=')
{
if(&&)
{
double temp;
double n1=[Link](nu1);
double n2=[Link](nu2);
if(n2==0 && [Link]("/"))
{
[Link](nu1+op+nu2+"=Zero division error");
nu1=op=nu2="";
}
else
{
if([Link]("+"))
temp=n1+n2;
else if ([Link]("-"))
temp=n1-n2;
else if ([Link]("/"))
temp=n1/n2;
else
temp=n1*n2;
String str=[Link](temp);
[Link](str);
nu1=[Link](temp);
op=nu2="";
}
}
else
{
nu1=op=nu2="";
[Link]("");
}
}
else {
if([Link]("") || [Link](""))
{
double temp;
double n1=[Link](nu1);
double n2 = [Link](nu2);
if(n2==0 && [Link]("/")){
[Link](nu1+op+nu2+"=Zero division error");
nu1=op=nu2="";
}
else {
if([Link]("+"))
temp=n1+n2;
else if ([Link]("-"))
temp=n1-n2;
else if ([Link]("/"))
temp=n1/n2;
else
temp=n1*n2;
nu1=[Link](temp);
op=button;
nu2="";
}
}
[Link](nu1+op+nu2);
}
}
}
Output:
Program – 12
Filename : [Link]
import [Link].*;
import [Link].*;
class MyClient
{
public static void main (String args[]) throws Exception
{
Socket s=new Socket("localhost",49682);
DataInputStream din=new DataInputStream([Link]());
DataOutputStream dout=new DataOutputStream([Link]());
BufferedReader br=new BufferedReader (new InputStreamReader([Link]));
String str="",str2="";
while()
{
str=[Link]();
[Link](str);
[Link]();
str2=[Link]();
[Link]("Server Says:" +str2);
}
[Link]();
[Link]();
}
}
Filename : [Link]
import [Link].*;
import [Link].*;
class MyServer
{
public static void main(String args[]) throws Exception
{
ServerSocket ss=new ServerSocket(49682);
Socket s=[Link]();
DataInputStream din=new DataInputStream([Link]());
DataOutputStream dout=new DataOutputStream([Link]());
BufferedReader br=new BufferedReader (new
InputStreamReader([Link]));
String str="",str2="";
while()
{
str=[Link]();
[Link]("Client says:" +str);
str2=[Link]();
[Link](str2);
[Link]();
}
[Link]();
[Link]();
[Link]();
}
}
Output:
MyClient:
Microsoft Windows [Version 10.0.22000.2538]
(c) Microsoft Corporation. All rights reserved.
C:\Users\User>d:
D:\>cd New folder (5)\JLab
D:\New folder (5)\JLab>set path="C:\Program Files (x86)\Java\jdk1.6.0\bin"
D:\New folder (5)\JLab>javac [Link]
D:\New folder (5)\JLab>java MyClient
Hi
Server Says:Hello
How are you?
Server Says:I am fine.
stop
Server Says:stop
D:\New folder (5)\JLab>
MyServer:
Microsoft Windows [Version 10.0.22000.2538]
(c) Microsoft Corporation. All rights reserved.
C:\Users\User>d:
D:\>cd New Folder (5)\JLab
D:\New folder (5)\JLab>set path="C:\Program Files (x86)\Java\jdk1.6.0\bin"
D:\New folder (5)\JLab>javac [Link]
D:\New folder (5)\JLab>java MyServer
Client says:Hi
Hello
Client says:How are you?
I am fine.
Client says:stop
stop
D:\New folder (5)\JLab>