AJP Manual
AJP Manual
AIM:
PROCEDURE:
Step 10: Specify attributes such as <u>, <li> to display in list formation.
1
PROGRAM:
Index.html:
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
</body>
</html>
NewServlet.java:
import java.io.IOException;
import java.io.PrintWriter;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@WebServlet("/NewServlet")
response.setContentType("text/html;charset=UTF-8");
/* TODO output your page here. You may use following sample code. */
2
out.write("<h1>Welcome to Servlet<h1><br>")
3
OUTPUT:
4
RESULT:
Hence the program has been executed successfully and the output is verified.
AIM:
PROCEDURE:
Step 4: Click on the source packages .In that select default package.
Step 5: Create a new servlet by right clicking default packages then click new option. In the
Step 6: Type the code for servlet.Run the project(Right click the project , click run option .
5
PROGRAM:
Index.html:
<html>
<head>
<title>Purchase Order</title>
</head>
<body>
<h1>Please tell about product </h1>
<form action="NewServlet">
Purchase Order Number:<input type="text" name="product_no">
Product Name:<input type="text" name="product_name">
address:<input type="text" name="address"><br>
Phone Number:<input type="text" name="phone_no"><br>
<p>
Items to be ordered:
<select name="JeanType">
<option value="Lenin">Lenin</option>
<option value="S-Kumar">S-Kumar</option>
<option value="V-Star">V-Star</option>
<option value="Peter">Peter</option>
</select>
<br>
Ordered Date:<input type="date" name="od">
Amount:<input type="number" name="amt">
<input type="submit">
</form>
</body>
6
</html>
NewServlet.java:
import java.io.IOException;
import java.io.PrintWriter;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
public class NewServlet extends HttpServlet
{
protected void service(HttpServletRequest request, HttpServletResponse response)throws
ServletException, IOException
{
String product_no=request.getParameter("product_no");
String product_name=request.getParameter("product_name");
String address=request.getParameter("address");
String phone_no=request.getParameter("phone_no");
String JeanType=request.getParameter("JeanType");
String od=request.getParameter("od");
int amt=Integer.parseInt(request.getParameter("amt"));
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.write("<h2>Following data received successfully...</h2><br>");
pw.write("<h2>Product no:"+product_no+"</h2><br>");
pw.write("<h2>Product name:"+product_name+"</h2><br>");
pw.write("<h2>Address:"+address+"</h2><br>");
7
pw.write("<h2>Phone no:"+phone_no+"</h2><br>");
pw.write("<h2>JeanType:"+JeanType+"</h2><br>");
pw.write("<h2>Ordered Date:"+od+"</h2><br>");
pw.write("<h2>Amount:"+amt+"</h2><br>");
pw.write("</h2><br>");
}
}
8
OUTPUT:
9
RESULT:
Hence the program has been executed successfully and the output is verified.
AIM:
To develop a program for calculating the percentage of marks of a student using JSP.
PROCEDURE:
10
PROGRAM:
index.html:
<html>
<head>
</head>
<body>
<center>
<h1>student marks</h1>
<b><input type="submit"></b>
</form>
</center>
</body>
</html>
newjsp.jsp:
<!DOCTYPE html>
11
<html>
<body>
<%
int java=Integer.parseInt(request.getParameter("java"));
int AI=Integer.parseInt(request.getParameter("AI"));
int AOS=Integer.parseInt(request.getParameter("AOS"));
int PHP=Integer.parseInt(request.getParameter("PHP"));
int WS=Integer.parseInt(request.getParameter("WS"));
int c=java+AI+AOS+PHP+WS;
double avg=c/5;
if(avg>90)
else if(avg>=80)
else if(avg>=70)
else if(avg>=60)
else
12
out.println("Your grade is E \n");
%>
</body>
</html>
OUTPUT:
13
RESULT:
Hence the program has been executed successfully and the output is verified.
AIM:
PROCEDURE:
14
PROGRAM:
index.html:
<html>
<body>
<p>
Items to be ordered:
<select name="JeanType">
<option value="Lenin">Lenin</option>
<option value="Otto">Otto</option>
<option value="S-Kumar">S-Kumar</option>
<option value="V-Star">V-Star</option>
<option value="Jockey">Jockey</option>
<option value="Peter">Peter</option>
<option value="Pantaloon">Pantaloon</option>
15
</select>
<br>
<input type="Submit">
</form>
</body>
</html>
newjsp.jsp:
<!DOCTYPE html>
<html>
<body>
<%
String pid=request.getParameter("pid");
String cname=request.getParameter("cname");
String cadd=request.getParameter("cadd");
String cl=request.getParameter("cl");
String JeanType=request.getParameter("JeanType");
String od=request.getParameter("od");
int amt=Integer.parseInt(request.getParameter("amt"));
%>
</body>
</html>
16
OUTPUT:
17
RESULT:
Hence the program has been executed successfully and the output is verified.
AIM:
PROCEDURE:
Step 4: select text and design a employee pay slip from using html.
Step 5: Right click on Project name and payslip -> new ->jsp.
Step 8: Display employee pay slip with according to the user input value
18
PROGRAM:
index.html:
<html>
<head>
</head>
<body>
<table>
19
<tr><td><input type="submit" value="Evaluate"></td><!-- comment -->
</table>
</body>
</html>
emp20.jsp:
<!DOCTYPE html>
<html>
<head>
</head>
<body bgcolor="beige">
<%
String ename=request.getParameter("ename");
String dept=request.getParameter("dept");
String des=request.getParameter("des");
double bsal=Double.valueOf(request.getParameter("bsal"));
double ta=Double.valueOf(request.getParameter("ta"));
double ta2=bsal*ta/100;
double da=Double.valueOf(request.getParameter("da"));
double da2=bsal*da/100;
double hra=Double.valueOf(request.getParameter("hra"));
double hra2=bsal*hra/100;
double pf=Double.valueOf(request.getParameter("pf"));
20
double pf2=bsal*pf/100;
double lic=Double.valueOf(request.getParameter("lic"));
double lic2=bsal*lic/100;
double allowance;
double deduction;
double gsal;
double netsal;
allowance=(bsal*ta)/100+(bsal*da)/100+(bsal*hra)/100+(bsal*pf)/100;
deduction= (bsal*pf)/100+(bsal*lic)/100;
gsal=bsal+allowance;
netsal=gsal-deduction;
%>
<center>
Salary statement</font></h2></caption>
<tr><th>allowance</th><th>percentage</th><th>amount</th></tr>
<tr align=center><td>TA</td><td><%=ta%></td><td><%=ta2%></td></tr>
<tr align=center><td>DA</td><td><%=da%></td><td><%=da2%></td></tr>
<tr align=center><td>HRA</td><td><%=hra%></td><td><%=hra2%></td></tr>
<tr><th>Deductions</th><th>Percentage</th><th>Amount</th></tr>
<tr align=center><td>PF</td><td><%=pf%></td><td><%=pf2%></td></tr>
<tr align=center><td>LIC</td><td><%=lic%></td><td><%=lic2%></td></tr>
21
<tr><td>Gross salary</td><td colspan=2><%=gsal%></td></tr>
</fontcolor>
</table>
</center>
</body>
</html>
OUTPUT:
22
RESULT:
Hence the program has been executed successfully and the output is verified.
AIM:
To write a program using JDBC for creating a table, inserting, deleting records and list
PROCEDURE:
Step 3: Create a Java Project. File → New Project; a window will appear. Select Java from
the Categories list and Java Application from the Projects list. Click Next.
PROGRAM:
package OracleCon;
import java.sql.*;
class OracleCon
try
Statement stmt=con.createStatement();
24
//step5 close the connection object
con.close();
catch(Exception e)
System.out.println(e);
OUTPUT:
25
RESULT:
Hence the program has been executed successfully and the output is verified.
EX-NO : 7
Write a program using java servlet to handle form data.
AIM:
PROCEDURE:
Step 4: Click on the java web and then select web application.
Step 5: Enter the project name ,click on next-select the server name as Glassfish server and
click finish.
26
Step 6: Open index.html type a coding to create simple form.
Step 7: Click on the source packages .In that select default package.
Step 8: Create a new servlet by right clicking default packages then click new option. In the
Step 9: Type the code for servlet.Run the project(Right click the project , click run option
PROGRAM:
index.html:
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<br><br>
27
gender:<input type="radio" name="gender" value="male" checked>
</form>
</body>
</html>
myservlet.java:
import java.io.IOException;
import java.io.PrintWriter;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
String un=request.getParameter("uname");
String password=request.getParameter("password");
String em=request.getParameter("email");
String ge=request.getParameter("gender");
String[] co=request.getParameterValues("course");
28
response.setContentType("text/html");
PrintWriter pw=response.getWriter();
pw.write("<h3>username:"+un+"</h3>");
pw.write("<h3>password:"+password+"</h3>");
pw.write("<h3>email:"+em+"</h3>");
pw.write("<h3>gender:"+ge+"</h3>");
pw.write("<h3>course");
for(String c:co)
pw.write(c+"");
pw.write("</h3>"); } }
OUTPUT:
29
RESULT:
Hence the program has been executed successfully and the output is verified.
AIM:
To write a simple servlet program to create a table of all the headers, it received along with
PROCEDURE:
30
Step 3: Go to file newproject .
PROGRAM:
31
OUTPUT:
32
RESULT:
Hence the program has been executed successfully and the output is verified.
AIM:
PROCEDURE:
33
Step 2: open netbeans IDE 7.3.1
Step 4: Type to start a session, Create a jsp file (index. Jsp). In the form element use the
action attribute to navigate the user to the firstpage.jsp file after enter the username and
password.
Step 5: Verification of user name and password in first page.jsp file. Once the user name and
password are correct , then navigate to the second page.jsp, else prompt theuser to enter the
proper credentials.
PROGRAM:
index.html:
<html>
<head>
<body>
</font><br><br>
34
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
newjsp.jsp:
<!DOCTYPE html>
<html>
<head>
<title>JSP Page</title>
</head>
<body>
<%
{ session.setAttribute("username", name);
response.sendRedirect("newjsp1.jsp");}
else {
response.sendRedirect("index.html");
%>
</body>
</html>
newjsp1.jsp:
<!DOCTYPE html>
<html>
<head>
35
<title>Welcome in the Program of Session</title>
</head>
<body>
<font size = 5>Hello <%= session.getAttribute("username") %> you are an authorized person</font>
</body>
</html>
OUTPUT:
36
RESULT:
Hence the program has been executed successfully and the output is verified.
AIM:
PROCEDURE:
37
Step 1:Start the process.
Step 5:Compile the implementation class and create the stub and skeleton object using the
RMI tool.
PROGRAM:
AddRem.java:
38
AddRemImpl.java:
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
return(a+b);
server.java:
import java.rmi.*;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
super();
return n1+n2;
39
Try
Registry reg=LocateRegistry.createRegistry(9999);
System.out.println("Server is running");
catch(Exception e){
System.out.println(e);
Client.java:
try
System.out.println("Addition is :"+ad.addNum(34,4));
catch(RemoteException e)
40
{
System.out.println(e);
OUTPUT:
Addition is 38.
41
RESULT:
Hence the program has been executed successfully and the output is verified.
AIM:
PROCEDURE:
42
Step 1: – Create a blank Java project and name it Java Calculator. Uncheck the Main class
Step 2: – To add a Jframe, right click the project name in the Project window.
Step 3: – To the right of the Jframe, there is a Palette with a set of controls on it. Click the
Step 4: – Select the Button and drag it to the Jframe form. Change the text and the Variable
Step5: – Change the Variable Name to btn One as we did for the text Field. Enter the value 1
for the text by selecting the properties. Do the same for all the buttons by changing the text
Step6: – Double click on any of the button. This will take the user to the source section where
PROGRAM:
package simplecalc;
import java.applet.Applet;
import java.awt.Frame;
43
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
public static final String[] TEXT = {"AC", "BSp", "%", "/", "7", "8", "9", "*", "4", "5", "6", "-","1", "2", "3", "+", "RSET",
"0", ".", "="};
TextField t1;
TextField t2;
title.setTitle("Simple Calculator");
setLayout(null);
add(t1);
add(t2);
int x = 50;
int y = 115;
int k = 1;
if (k % 4 == 0) { x = 50;y += 50;k = 0;
k++;
add(b[i]);
b[i].addActionListener(this);
System.out.println("generating result");
t1.setText(calculate(value));
value.setLength(0);
else if (s.equalsIgnoreCase("AC"))
value.setLength(0);t2.setText("");
else if (s.equalsIgnoreCase("BSp"))
45
System.out.println("BSp: Erasing a character");
value.setLength(value.length() - 1);
t2.setText(value.toString());
else if (s.equalsIgnoreCase("RSET"))
value.setLength(0);
t1.setText("");
t2.setText("");
else
value.append(s);
t2.setText(value.toString());
Objectresult = null;
try
result = engine.eval(sb.toString());
System.out.println(result);
46
catch (ScriptException ex)
result = "Error";
return result.toString();
OUTPUT:
47
RESULT:
Hence the program has been executed successfully and the output is verified.
EX-NO : 12 Program to send a text message to another system and receive the
text message from the system (Use Socket Programming)
AIM:
48
To program to send a text message to another system and receive the text message from
PROCEDURE:
Step8: Make a connection using socket class and close the class.
PROGRAM:
49
Myserver.java
import java.io.*;
import java.net.*;
try
Socket s=receive.accept();
//establishes connection
String str=(String)dis.readUTF();
System.out.println("message="+str);
dis.close();
s.close();
receive.close();
catch(Exception e)
System.out.println(e);
Myclient.java
import java.io.*;
50
import java.net.*;
try
//String msg;
dout.writeUTF("Hello Server");
dout.flush();
dout.close();
sendsocket.close();
catch(Exception e)
System.out.println(e);
OUTPUT:
51
RESULT:
Hence the program has been executed successfully and the output is verified.
52