AJP Lab Programs
AJP Lab Programs
AJP Lab Programs
To write a Java Program to design an interface for Stack ADT and implement Stack ADT
using both Array and Linked List.
2. Write a Java program that loads names and phone numbers from a text file where the data
is organized as one line per record and each field in a record are separated by a tab (\t). It
takes a name or phone number as input and prints the corresponding other value from the
hash table (hint: use hash tables).
3. Write a Java program that connects to a database using JDBC and does add, delete,
modify and retrieve operations
5. Develop and demonstrate a HTML5 document that illustrates the use of ordered list,
unordered list, table, borders, padding, color, and the <div> & <span> tag.
c. Animation
9. Create tables in the database which contain the details of items (books in our case Like
Book name, Price, Quantity, Amount) of each category. Modify your catalogue page in
such a way that you should connect to the database and extract data from the tables and
display them in web page using JDBC.
10. Using java servlets and JDBC store and retrieve the following information from a
database:
a. Name
b. Password
c. Email id
d. Phone number
REGISTER.HTML
<html>
<body>
<table>
<tr>
</tr>
<tr>
</tr>
<tr>
<tr>
</tr>
<tr>
</tr>
</table>
</form>
</body>
</html>
REGISTER.JAVA
import java.io.*;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String n=request.getParameter("userName");
String p=request.getParameter("userPass");
String e=request.getParameter("userEmail");
long c=request.getParameter("phno");
try{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/vvit”,”root”,”root”);
ps.setString(1,n);
ps.setString(2,p);
ps.setString(3,e);
ps.setString(4,c);
int i=ps.executeUpdate();
if(i>0)
out.close();
}
Web.xml:
<web-app>
<servlet>
<servlet-name>Register</servlet-name>
<servlet-class>Register</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Register</servlet-name>
<url-pattern>/servlet/Register</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Display</servlet-name>
<servlet-class>Display</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Display</servlet-name>
<url-pattern>/servlet/Display</url-pattern>
</servlet-mapping>
</web-app>
Display.html
<form action="servlet/Display">
</form>
Display.java
import java.io.*;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String name=request.getParameter("uname");
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/vvit”,”root”,”root”);
ResultSet rs=ps.executeQuery();
out.print("</tr>");
/* Printing result */
while(rs.next())
{
out.print("<tr><td>"+rs.getString(1)+"</td><td>"+rs.getString(2)+"
</td><td>"+rs.getString(3)+"</td><td>"+rs.getInt(4)+"</td></tr>");
out.print("</table>");
finally{out.close();}
OUTPUT:
11. Demonstrate Cookie and Session Management in Servlets.
Index.html
FirstServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String n=request.getParameter("userName");
out.print("Welcome "+n);
out.close();
}catch(Exception e){System.out.println(e);}
}
}
SecondServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
Cookie ck[]=request.getCookies();
out.print("Hello "+ck[0].getValue());
out.close();
}catch(Exception e){System.out.println(e);}
}
web.xml
<web-app>
<servlet>
<servlet-name>s1</servlet-name>
<servlet-class>FirstServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s1</servlet-name>
<url-pattern>/servlet1</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>s2</servlet-name>
<servlet-class>SecondServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>s2</servlet-name>
<url-pattern>/servlet2</url-pattern>
</servlet-mapping>
</web-app>
OUTPUT:
12. Write a JSP program to conduct online examination and to display student mark list
available in a database.
ExamServer.jsp:
ExamClient.HTML:
<html>
<head>
<title>Online Exam Client</title>
<style type="text/css">
body{background-color:black;font-family:courier;color:blue}
</style>
</head>
<body>
<h2 style="text-align:center">ONLINE EXAMINATION</h2>
<h3>Answer the following questions (5 marks for each correct answer)</h3>
<hr/>
<form name="examForm" method="post" action="ExamServer.jsp">
1. All computers must have <br/>
<input type="radio" name="ans1" value="Operating System">Operating System
<input type="radio" name="ans1" value="Application Software">Application Software
<input type="radio" name="ans1" value="CD Drive">CD Drive
<input type="radio" name="ans1" value="Microsoft word">Microsoft word
<br/><br/>
2. The term PC means <br/>
<input type="radio" name="ans2" value="Private Computer">Private Computer
<input type="radio" name="ans2" value="Professional Computer">Professional Computer
<input type="radio" name="ans2" value="Personal Computer">Personal Computer
<input type="radio" name="ans2" value="Personal Calculator">Personal Calculator
<br/><br/>
3.C was developed by?<br/>
<input type="radio" name="ans3" value="Dennis Ritchie">Dennis Ritchie
<input type="radio" name="ans3" value="Stroustrup">Stroustrup
<input type="radio" name="ans3" value="David Ritchie">David Ritchie
<input type="radio" name="ans3" value="Charles Babbage">Charles Babbage
<br/><br/>
<input type="submit" value="Check Your Result"/>
</form>
</body>
</html>
Writecookies
One.jsp
<%
// Creating cookies for name and age.
Cookie name = new Cookie("User_name", request.getParameter("User_name"));
Cookie age = new Cookie("Age", request.getParameter("Age"));
Cookie gender = new Cookie("Gender", request.getParameter("Gender"));
// Setting expiry date
name.setMaxAge(60*60*24);
age.setMaxAge(60*60*24);
gender.setMaxAge(60*60*24);
// Add both the cookies in the response header.
response.addCookie( name );
response.addCookie( age );
response.addCookie( gender );
%>
<html>
<head>
<title>Set Cookies</title>
</head>
<body>
<h2>--DataFlair--<h2>
<h2>Here we are setting Cookies</h2>
<ul>
<li><p><b>User Name:</b>
<%= request.getParameter("User_name")%>
</p></li>
<li><p><b>Age:</b>
<%= request.getParameter("Age")%>
</p></li>
<li><p><b>Gender:</b>
<%=request.getParameter("Gender")%>
</p></li>
</ul>
</body>
</html>
Hello.jsp
<html>
<body>
<form action = "write.jsp" method = "GET">
User Name: <br/><input type = "text" name = "User_name">
<br />
Age: <br/><input type = "text" name = "Age" />
<br/>
Gender:</br><input type = "text" name = "Gender">
<br/>
<input type = "submit" value = "Go" />
</form>
</body>
</html>
Read Cookies:
Two.jsp
<html>
<head>
<title>Read Cookies</title>
</head>
<body>
<h1>Reading Cookies that we set</h1>
<%
Cookie my_cookie = null;
Cookie[] my_cookies = null;
// Get an array of Cookies associated with the this domain
my_cookies = request.getCookies();
if( my_cookies != null ) {
out.println("<h2> Found Cookies Name and Value</h2>");
for (int i = 0; i < my_cookies.length; i++) {
my_cookie = my_cookies[i];
out.print("Name : " + my_cookie.getName( ) + ", ");
out.print("Value: " + my_cookie.getValue( )+" <br/>");
}
} else {
out.println("<h2>No cookies founds</h2>");
}
%>
</body>
</html>
OUTPUT:
15. Write a program to prompt the user for a hostname then looks up the IP address
for the hostname and read the webpage name then display the contents of the
webpage.