Ip Record
Ip Record
NO:1
IMAGE MAPPING USING HTML
DATE:07.04.2022
AIM:
To create a web page which includes a map and display the related
information when a hot spot is clicked in the map.
PROCEDURE:
STEP1: Create a html file with map tag .
STEP2: Set the source attribute of the img tag to the location of the image and
also set the use map attribute .
STEP3: Specify an area with name, shape and href set to the appropriate
values.
STEP4: Repeat step 3 as many hot spots you want to put in the map.
STEP5: Create html files for each and every hot spot the user will select.
CODING:
Map.html:
<html>
<head>
<title>India map</title>
</head>
<body>
<img src="map.jpg" usemap="#image_map">
<map name="image_map">
1
<area alt="" title="" href="tamilnadu.html" coords="620,1558,697,1706"
shape="rect">
<area alt="" title="" href="kerala.html" coords="521,1653,89" shape="circle">
<area alt="" title="" href="karnataka.html"
coords="436,1371,561,1239,604,1472,502,1500,494,1490" shape="poly">
<area alt="" title="" href="Maharashtra.html" coords="420,1011,637,1205"
shape="rect">
</map>
</body>
</html>
Tamilnadu.html:
<html>
<head>
<tittle>
</title>TAMILNADU</title>
</head>
<body bgcolor="banana yellow">
<u1 style="list-style-type:circle:">
<li><b>AREA</b>=130,058KMSQ
<li><b>CAPITAL</b>=CHENNAI
<li><b>CHIEF MINISTER</b>=Stalin</u1>
<p>Tamil Nadu, a South Indian state, is famed for its Dravidian-style Hindu
temples.<br>
In Madurai, Meenakshi Amman Temple has high ‘gopuram’ towers ornamented
with colourful figures.<br>
On Pamban Island, Ramanathaswamy Temple is a pilgrimage site. <br>
The town of Kanyakumari, at India’s southernmost tip, is the site of ritual sunrises.
<br>
Capital Chennai is known for beaches and landmarks
</p>
2
</body>
</html>
Kerala.html:
<html>
<head>
<tittle>
</title>KERALA</title>
</head>
<body bgcolor="sky blue">
<u1 style="list-style-type:circle:">
<li><b>AREA</b>=38,863kmsq
<li><b>CAPITAL</b>=Thiruvanathapuram
<li><b>CHIEF MINISTER</b>=Pinarayi vijayan</u1>
<p>Kerala, a state on India's tropical Malabar Coast, has nearly 600km of Arabian
Sea shoreline.<br>
It's known for its palm-lined beaches and backwaters, a network of canals.<br>
Inland are the Western Ghats, mountains whose slopes support tea, coffee and
spice plantations as well as wildlife.<br>
National parks like Eravikulam and Periyar, plus Wayanad and other sanctuaries,
are home to elephants, langur monkeys and tigers.
<\p>
</body>
</html>
Karnataka.html:
<html>
<head>
<tittle>
</title>KARNATAKA</title>
</head>
<body bgcolor="ivory">
3
<u1 style="list-style-type:circle:">
<li><b>AREA</b>=191,791kmsq
<li><b>CAPITAL</b>=Bangalore
<li><b>CHIEF MINISTER</b>=Basavaraj Bommai</u1>
<p>Karnataka is a state in southwest India with Arabian Sea coastlines.<br>
The capital, Bengaluru is a high-tech hub known for its shopping and
nightlife.<br>
To the southwest, Mysore is home to lavish temples including Mysore Palace,
former seat of the region’s maharajas.<br>
Hampi, once the medieval Vijayanagara empire’s capital, contains ruins of Hindu
temples, elephant stables and a stone chariot.
</p>
</body>
</html>
Maharashtra.html:
<html>
<head>
<tittle>
</title>MAHARASHTRA</title>
</head>
<body bgcolor="pistachio">
<u1 style="list-style-type:circle:">
<li><b>AREA</b>=307,713 kmsq
<li><b>CAPITAL</b>=Mumbai
<li><b>CHIEF MINISTER</b>= Eknath Shinde</u1>
<p>Maharashtra is a state in the western and central peninsular region of India
occupying a substantial portion of the Deccan Plateau.<br>
Maharashtra is the second-most populous state in India and the second-most
populous country subdivision globally.
</p>
</body>
</html>
4
OUTPUT:
5
6
RESULT:
Thus the creation of a web page which includes a map and display the
related in-formation when a hot spot is clicked in the map was executed
successfully.
7
EX.NO:2
CASCADING STYLE SHEETS
DATE:21.04.2022
AIM:
To create a web page that displays college information using various style
sheet
PROCEDURE:
STEP1: Create a web page with frame sets consisting two frames
STEP2: In the first frame include the links
STEP3: In the second frame set display the web page of the link
STEP4: Create a external style sheets
STEP5: Create a embedded style sheets
STEP6: Create a inline and internal style sheets and make it link to the
external style sheets
CODING:
External.css:
h3{font-family:arial;font-size:20;color:cyan}
table{border-color:green}
td{font-size:20pt;color:magenta}
Style.css:
<html>
<head><h1><center>SONA COLLEGE OF TECHNOLOGY</center></h1>
<title>USE of STYLESHEETS
</title>
8
<link rel="stylesheet" href="External.css" type="text/css"> <!-- External Style
Sheet -->
<style type="text/css"> <!-- Internal Style Sheet -->
.S1{font-family:verdana; font-style:italic; color:red; text-align:center}
.S2{font-family:tahoma; font-style:italic; font-size:20; text-align:center;}
font{font-family:georgia; color:blue; font-size:20}
ul{list-style-type:circle}
</style>
</head>
<body>
<p>HOME|ADMISSION|SPORTS|ACADEMICS|FACILITIES|CONTACT</P>
<br>
<br>
<font>
<h2>List of Courses offered</h2>
<ul>
<li>CSE</li>
<li>IT</li>
<li>ECE</li>
<li>EEE</li>
<li>MECH</li>
<li>Civil</li>
</ul>
</font>
9
<h3>Pass percentage in year 2019</h3>
<table width="100%" cellspacing="2" cellpadding="2" border="5">
<tr>
<th>Sl.No</th>
<th>Dept</th>
<th>Pass Percentage</th>
</tr>
<tr>
<td align="center">1</td>
<td align="center">CSE</td>
<td align="center">80</td>
</tr>
<tr>
<td align="center">2</td>
<td align="center">ECE</td>
<td align="center">78</td>
</tr>
<tr>
<td align="center">3</td>
<td align="center">Mech</td>
<td align="center">75</td>
</tr>
</table>
<ol style="list-style-type:lower-alpha">
10
<p style="font-size:20pt;color:purple">
Sona college of Technology</p> <!-- InlineStyle Sheet -->
<p class="S2"> Run by Anna University, Chennai<br>
It is approved by AICTE.
<br>
</p>
<center><font><p>Sona college of Technology<font></p></center>
<center><font>Located in Salem,Tamil Nadu</font></center>
</body>
</html>
OUTPUT:
11
RESULT:
Thus the creation of a web page that displays college information using
various style sheets was successfully executed and verified.
12
EX.NO:3
JAVASCRIPT VALIDATION
DATE:28.04.2022
AIM:
PROCEDURE:
STEP3 : Validate the required fields like Name,Account number using javascript
validation.
CODING:
Web.html:
<html>
<head>
<title>Amazon</title>
</head>
<body bgcolor="blue"><center>
<strong><h1>Welcome to AMAZON</h1></strong>
13
<h4>For Books</h4>
<form method="post" action="profilelogin.html" target=_blank >
<input type="submit" value="Click Here">
</form>
</center>
</body>
</html>
Profilelogin.html:
<html>
<head>
<title>login page</title> </head>
<body bgcolor="blue"><center>
<script language="javascript">
function validate()
{
name= document.getElementById("name").value;
password=document.getElementById("password").value;
if(name=="")
{
alert("Please enter user name");
return false;
}
else if(password=="")
{
14
alert("Please enter Password");
return false;
}
}
</script>
<strong><h1> AMAZON </h1></strong></center>
<table align="center"><tr>
<td><h4>User Name </h4></td>
<td><input type="text" id="name"></td></tr>
<tr><td><h4>Password</h4></td>
<td><input type="password" id="password"></td></tr>
<tr> <td> <form method="post" action="catlog.html" onsubmit="return
validate()">
<input type="submit" value="Login" >
</form>
</td> <td>
<form method="post" action="RegisterLogin.html" target=_blank>
<input type="submit" value="Sign In" > </form></td>
</tr> </table> </body>
</html>
Registerlogin.html:
<html>
<head>
<title>REGISTER</title> </head>
<body bgcolor="blue">
15
<center><strong> AMAZON </strong></center>
<script language="javascript">
function validate()
{
name = document.getElementById("name").value;
password =document.getElementById("password").value;
confirmpass =document.getElementById("confirmpass").value;
if(name=="")
{
alert("Please enter user name");
return false;
}
else if(password=="")
{
alert("Please enter Password");
return false;
}
if(password.length<8)
{
alert("Password length must be 8 characters");
return false;
}
if(password.length>15)
{
alert("Password lenth not exceed 15 characters");
16
return false;
}
if(confirmpass="")
{
alert=("please confirm the password");
return false;
}
}
</script>
<table align="left">
<tr> <td> <h4>User Name </h4> </td>
<td> <input type="text" id="name" > </td> </tr>
<tr> <td> <h4> Password </h4> </td>
<td> <input type="password" id="password"></td></tr>
<tr> <td> <h4>Confirm Password</h4></td>
<td><input type="password" id="confirmpass"></td></tr>
<tr><option>
<td> Male
<input type="radio" name="sex" id="male"></td>
<td>Female
<input type="radio" name="sex" id="female" ></td></option></tr><br>
<tr>
<td><h4>Address</h4></td>
<td><textarea name="address" rows=5 cols=20>
17
</textarea></td></tr>
<tr><td>
<form method="post" action="catlog.html" onclick="return validate()"
target=_blank>
<input type="submit" value="Sign In" >
</form></td><br><br>
<td><form method="post" action="RegisterLogin.html" target=_blank>
<input type="submit" value="Reset" ></td></tr><br><br></form>
Catlog.html:
<html>
<head>
<title>
books catalog</title>
</head>
<body bgcolor="blue">
<center><h1>AMAZON</h1></center>
<form method="post" action="shopping.html">
<left>
<table>
<tr>
<td><b><h3>Frontend Books</td>
<td></td></tr>
<tr>
<td></td>
18
<td><h4>C&Ds</td>
</tr>
<tr>
<td></td>
<td><h4>Ads</td>
</tr>
<tr>
<td></td>
<td><h4>JAVA
</td></tr>
<tr>
<td><b><h3>Backend Books</td>
<td></td>
</tr>
<tr>
<td></td>
<td><h4>Oracle</td>
</tr>
<tr>
<td></td>
<td><h4>Ms SQL Server
</td></tr>
<tr>
<td></td>
<td><h4>MySql </td>
19
</tr>
</table>
</h4>
<center>
<b>For buy one of these books<br>
</b><input type="submit" value="Click Here">
</center>
</form>
</body>
</html>
Shooping.html:
<html>
<head><title>shopping cart</title>
</head>
<body bgcolor="blue">
<center><h1>
Shopping Cart</h1></center>
<br><br><br><br><br>
<table align="center">
<tr>
<td>Text Books</td>
<td>
<select >
<optgroup label="select the book">
20
<option value="C&Ds">C&Ds
<option value="Ads">Ads
<option value="Java">Java
<option value="Oracle">Oracle
<option value="Ms SQL Server">Ms SQL Server
<option value="MySql">MySql
</optgroup>
</select>
</td></tr>
<tr>
<td>
Quantity</td>
<td>
<input type="text" name="quantity" id="quantity">
</td></tr>
<tr><td>
<form method="post" action="payment.html" >
<input type="submit" value="click" >
</form>
</td></tr>
</table>
<center>
<pre>Cost of one book is"500" + shipping "100"</pre>
</center>
</body> </table> </body>
21
</html>
Payment.html:
<html>
<head><title>payment</title></head>
<body bgcolor="blue">
<script language="javascript">
function check()
{
name=document.getElementById("name").value;
cvv= document.getElementById("cvv").value;
if(cvv.maxlength=3)
{
alert("cvv must contain only 3 value");
return false;
}
if(name=="")
{
alert("Account holder name should not be empty");
return false;
}
}
<center><h1>Payment By Credit Card</h1></center>
<br><br><br><br><br>
<table align="center">
22
<tr> <td>
<h4>Total Amount</h4></td>
<td><input type="text" name="amount" id="ta">
</td> </tr>
<tr>
<td><h4>Credit Card Number</td>
<td><input type="text" name="num" id="ccn"></td>
<td>
<form method="post" action="orderconform.html" onclick=”return check()”>
<input type="submit" value="OK">
</td></tr> </form>
</table> </body>
</html>
Orderconform.html:
<html>
<head><title>order conformation</title><M/head>
<body bgcolor="blue"> <center>
<h1><b>AMAZON</h1>
<pre><strong>
<b>Your order Is Conformed
</strong></pre>
<h2><b>THANK YOU</h2>
</center> </body> </html>
23
OUTPUT:
24
25
26
27
28
RESULT:
Thus the program Develop static pages (using only HTML) of an online
Book store is executed successfully.
29
EX.NO:4.A
AIM:
To write a java program for calculator from HTML form.
PROCEDURE:
Index.html
(1) Create a web page using HTML form that contains the fields such as two text
fields, and one submit button.
(2) Use the list filed to select the operations.
(3) Run the HTML program.
(4) Submit the form data to the server.
calculator.java
(1) Define the class server that extends the property of the class calculator.
(2) Handle the request from the client by using the method service() of calculator
class.
(3) Get the parameter names from the HTML form by using the method
getParameterNames().
(4) Get the parameter values from the HTML forms by using the method
getParameter().
(5) use the switch case for the arithematic operation performed on the HTML
form.
30
Index.html
<html>
<head>
<title>Calculator</title>
</head>a
<body>
<form action="calculator" method="get" name="frm">
Enter num1:<input name="txt1" type="text" />
Enter num2:
<input name="txt2" type="text" />
Operator
<select name="op">
<option value="Addition">Addition</option>
<option value="Subtraction">Subtraction</option>
<option value="multiplication">multiplication</option>
<option value="division">division</option>
</select>
<input type="submit" value="submit" />
</form>
</body>
</html>
31
calculator.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(urlPatterns = {"/calculator"})
public class calculator extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
32
switch (op) {
case "Addition":
out.println("Answer = "+(Integer.parseInt(n1) + Integer.parseInt(n2)));
break;
case "Subtraction":
out.println("Answer = "+(Integer.parseInt(n1) - Integer.parseInt(n2)));
break;
case "multiplication":
out.println("Answer = "+(Integer.parseInt(n1) * Integer.parseInt(n2)));
break;
default:
out.println("Answer = "+(Integer.parseInt(n1) / Integer.parseInt(n2)));
break;
}
}
}
33
OUTPUT:
34
RESULT:
Thus the given a java program to invoke servlets from HTML form is
executed successfully.
35
EX.NO:4.B
AIM:
To perform session tracking using hidden form fields.
PROCEDURE:
STEP 4:The second servlet will display the user information with greeting
message.
CODING:
HTML CODE:
<html>
<head>
<title>Session Tracking Using Hidden Form Field</title>
</head>
<body>
<form action="session" method=”get”>
Enter Name:<input type="text" name="username"/><br/>
Enter city:<input type="text" name="usercity"/><br/>
<input type="submit" value="submit"/>
</form>
</body>
</html>
36
SERVLET1 :
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class session extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)
{
try
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String n=request.getParameter("username");
String c=request.getParameter("usercity");
out.print("<form action=\"session1\">");
out.print("<input type='hidden' name='uname' value="+n+">");
out.print("<input type='hidden' name='usercity' value="+n+">");
out.print("<input type='submit' value='Just click here'>");
out.print("</form>");
out.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
SERVLET2:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
OUTPUT:
38
RESULT:
Thus the Java Program for Session Tracking Using Hidden Form Fields has
been executed successfully.
39
EX.NO:4.C
AIM:
To write a java program for session tracking a hit count. This servlet uses
session tracking to count the number of times a client has accessed it.
PROCEDURE:
TrackServlet.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet(urlPatterns = {"/TrackServlet"})
40
public class TrackServlet extends HttpServlet {
@Override
public void doGet(HttpServletRequest req,HttpServletResponse res) throws
ServletException,IOException
{
res.setContentType("text/html");
HttpSession session = req.getSession();
String heading;
Integer cnt=(Integer)session.getAttribute("cnt");
if(cnt==null)
{
cnt=0;
heading="Welcome you are accessing the page for the first time";
}
else
{
heading="Welcome once again";
cnt=cnt+1;
}
session.setAttribute("cnt",cnt);
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<head>");
out.println("</head>");
41
out.println("<body>");
out.println("<center>");
out.println("<h1>"+heading);
out.println("<h2>The number of previous access="+cnt);
out.println("</center>");
out.println("</body>");
out.println("</html>");
}
}
OUTPUT:
42
RESULT:
Thus, the above program has been executed successfully.
43
EX.NO:5
AIM:
To write java servlet programs to conduct online examination and to display
student mark list available in a database
PROCEDURE:
Client:
STEP1: In index.html on the client side declare the contents that you like to
transfer to the server using html form and input type tags.
STEP2: Create a submit button and close all the included tags.
Servlet:
STEP1: Import all necessary packages.
STEP2: Define a class that extends servlet.
STEP3: In the doPost() method, do the following:
• Set the content type of the response to "text/html".
• Create a writer to the response.
• Get a paratmeter from the request.
• If its value is equal to right answer then add 5 to mark variable.
• Similarly repeat step for all parameters.
• Display the result in an html format using the writer.
Student Mark List Database:
STEP1: Import necessary to java packages and javax packages and classes.
44
STEP2: Create a class that extends HttpServlet and implements ServletException
and IOException.
STEP3: In the doGet() method, do the following:
• Create a PrintWriter object.
• Open a connection with the data source name.
• Write a sql query and execute to get the resultset.
• Display the resultset information in html form.
Index.html:
<html>
<head>
<title>Online Exam Client</title>
<style type="text/css">
body{background-color:yellow;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.Who is called as the father of computer?<br/>
<input type="radio" name="ans1" value="Sachin">Sachin
<input type="radio" name="ans1" value="Stuart">Stuart
45
<input type="radio" name="ans1" value="Charles Babbage">Charles Babbage
<input type="radio" name="ans1" value="Napier">Napier
<br/><br/>
2.C++ was developed by?<br/>
<input type="radio" name="ans2" value="Dennis Ritchie">Dennis Ritchie
<input type="radio" name="ans2" value="None">None
<input type="radio" name="ans2" value="David Ritchie">David Ritchie
<input type="radio" name="ans2" value="John">John
<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>
ExamServer:
46
<head>
<title>Online Exam Server</title>
<style type="text/css">
body{background-color:yellowgreen;font-family:courier;color:blue}
</style>
</head>
<body>
<h2 style="text-align:center">ONLINE EXAMINATION</h2>
<p>
<a href="index.html">Back To Main Page</a>
</p>
<hr/>
<%
String str1=request.getParameter("ans1");
String str2=request.getParameter("ans2");
String str3=request.getParameter("ans3");
int mark=0;
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?zeroDate
TimeBehavior=convertToNull","root","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT * FROM examtab");
int i=1;
while(rs.next())
47
{
if(i==1)
{
String dbans1=rs.getString(1);
if(str1.equals(dbans1))
{
mark=mark+5;
}
}
if(i==2)
{
String dbans2=rs.getString(1);
if(str2.equals(dbans2))
{
mark=mark+5;
}
}
if(i==3)
{
String dbans3=rs.getString(1);
if(str3.equals(dbans3))
{
mark=mark+5;
}
}
48
i++;
}
if(mark>=10)
{
out.println("<h4>Your Mark Is : "+mark+"</h4>");
out.println("<h3>Congratulations....! You Are Eligible For The Next
Round...</h3>");
}
else
{
out.println("<h4>Your Mark is : "+mark+"</h4>");
out.println("<h3>Sorry....!! You Are Not Eligible For The Next Round...</h3>");
}
%>
</form>
</body>
</html>
49
OUTPUT:
50
RESULT:
Thus to write JSP programs to conduct online examination and to display
student mark list available in a database was successfully executed and verified.
51
EX.NO:6
SHOPPING CART
DATE:09.06.2022
AIM:
To write java servlet programs to create the shopping cart and add the
quantity of the book in the shopping basket.
PROCEDURE:
STEP 1: Open the netbean and click a new project.
STEP 2:In that click the servlet form and enter the servlet name and create the
servlet.
STEP 3:Define the class server that extends the property of the class shoppingcart.
STEP 4:Enter the quantity of the product and click add to cart
STEP 5:Display the shopping basket.
CODING:
ShoppingCart.java:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class ShoppingCart extends HttpServlet {
52
String [] items = new String [] {
"Samsung A30", "MI 108 CM Android TV", "HP USB Pend Drive 32GB",
"DELL Core i5, 8GB RAM, 1TB HDD Laptop" };
protected void processRequest(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("<center><h3>ABC SHOPPING CART </h3></center>");
out.println("<hr>");
HttpSession session = request.getSession();
int [] purchases = (int [])session.getAttribute("purchases");
if ( purchases == null ) {
purchases = new int [ items.length ];
session.setAttribute( "purchases", purchases );
}
out.println( "<html><head><title>Shopping Cart</title>" +
"</title></head><body><p>" );
if ( request.getParameter("checkout") != null )
out.println("<h1>Thanks for ordering!</h1>");
else {
if ( request.getParameter("add") != null ) {
addPurchases( request, purchases );
out.println( "<h1>Purchase added. Please continue</h1>");
} else {
if ( request.getParameter("clear") != null )
53
for (int i=0; i<purchases.length; i++)
purchases[i] = 0;
out.println("<h1> Please Select Your Items! </h1>");
}
doForm( out, request.getRequestURI() );
}
showPurchases( out, purchases );
out.close();
}
void addPurchases( HttpServletRequest request, int [] purchases ) {
for (int i=0; i<items.length; i++) {
String added = request.getParameter( items[i] );
if ( added !=null && !added.equals("") )
purchases[i] += Integer.parseInt( added );
}
}
void doForm( PrintWriter out, String requestURI ) {
out.println( "<form method=POST action="+ requestURI +">" );
for(int i=0;i< items.length;i++)
out.println( "Quantity <input name=\"" + items[i]+ "\" value=0 size=3> of: "
+ items[i] + "<br>");
out.println( "<p><input type=submit name=add value=\"Add To Cart\">" +
"<input type=submit name=checkout value=\"Check Out\">" + "<input
type=submit name=clear value=\"Clear Cart\">"
+ "</form>" );
}
54
void showPurchases( PrintWriter out, int [] purchases )
throws IOException {
out.println("<hr><h2>Your Shopping Basket</h2>");
for (int i=0; i<items.length; i++)
if ( purchases[i] != 0 )
out.println( purchases[i] +" "+ items[i] +"<br>" );
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}
}
55
OUTPUT:
56
RESULT:
Thus, the above program has been executed successfully.
57
EX.NO:7
BOOK INFORMATION USING JSP AND MYSQL
DATE:16.06.2022 CONNECTIVITY
AIM:
To create and save an JSP document at the server, which contain ten Book
information. To write a program which takes Book title as an input and returns the
user details by taking the Book information from the JSP document.
PROCEDURE:
STEP1: Save BOOK information in the JSP file on the specific location.
STEP2:Add the library my sql jdbc dirver and add the services
STEP3: Create and establish the connection between html file and JSP file.
STEP4: Get the BOOK TITLE as input
STEP5: Display the BOOK information.
Index.html:
<!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>Book Catalog</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
58
<body>
<h3>ABC Book Store </h3>
<hr>
<a href="BookDisplay.jsp"> View All Books </a><BR>
<form name="f1" action="BookSearch.jsp" method="get">
<table>
<tr>
<td>Enter the Book title to search </td>
<td><input type="text" name ="bname" value=""/></td>
</tr>
<td colspan="2"><input type="submit" value="Search" /></td>
</tr>
</table>
</form>
</body>
</html>
Booksearch.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<html>
<head>
<title>display data from the table using jsp</title>
59
</head>
<body>
<h2>Book Catalog</h2>
<%
try {
/* Create string of connection url within specified format with machine
name, port number and database name. Here machine name id localhost and
database name is student. */
60
String ss= request.getParameter("bname");
// sql query to retrieve values from the secified table.
String QueryString = "SELECT * from books where bname like '"+ss+"%'";
rs = statement.executeQuery(QueryString);
%>
<TABLE cellpadding="15" border="1" style="background-color: #ffffcc;">
<%
while (rs.next()) {
%>
<TR>
<TD><%=rs.getInt(1)%></TD>
<TD><%=rs.getString(2)%></TD>
<TD><%=rs.getString(3)%></TD>
<TD><%=rs.getString(4)%></TD>
<TD><%=rs.getString(5)%></TD>
</TR>
<% } %>
<%
// close all the connections.
rs.close();
statement.close();
connection.close();
} catch (Exception ex) {
%>
</font>
61
<font size="+3" color="red"></b>
<%
out.println(ex);
}
%>
</TABLE><TABLE>
<TR>
<TD><FORM ACTION="index.html" method="get" >
<button type="submit"><--back</button></TD>
</TR>
</TABLE>
</font>
</body>
</html>
Bookdisplay.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<html>
<head>
<title>display data from the table using jsp</title>
</head>
<body>
<h2>Book Catalog</h2>
62
<%
try {
63
<%
// close all the connections.
rs.close();
statement.close();
connection.close();
} catch (Exception ex) {
%>
</font>
<font size="+3" color="red"></b>
<%
out.println("Unable to connect to database.");
}
%>
</TABLE><TABLE>
<TR>
<TD><FORM ACTION="index.html" method="get" >
<button type="submit"><-- back</button></TD>
</TR>
</TABLE>
</font>
</body>
</html>
64
OUTPUT:
RESULT:
Thus the Book information has been successfully executed.
65
EX.NO:8
XML PARSING
DATE:23.06.2022
AIM:
To create and save an XML document at the server, which contain ten users
information. To write a program which takes user id as an input and returns the
user details by taking the user information from the XML document.
PROCEDURE:
• Save Students information in the XML file on the specific location.
• Create and establish the connection between html file and XML file.
• Get the user ID as input
• Display the student’s information.
StudentDetails.xml :
<?xml version="1.0" encoding="UTF-8"?>
<Student>
<PersonDetails>
<id>101</id>
<name>Anand</name>
<city>Madurai</city>
<Branch>CSE</Branch>
<Year>I</Year>
</PersonDetails>
<PersonDetails>
<id>102</id>
<name>Anu</name>
66
<city>Konam</city>
<Branch>CSE</Branch>
<Year>II</Year>
</PersonDetails>
<PersonDetails>
<id>4041</id>
<name>Sathish</name>
<city>Krishnagiri</city>
<Branch>CSE</Branch>
<Year>III</Year>
</PersonDetails>
<PersonDetails>
<id>104</id>
<name>Monica</name>
<city>Nellai</city>
<Branch>CSE</Branch>
<Year>III</Year>
</PersonDetails>
</Student>
LogIn.html :
<!DOCTYPE html>
<html>
<head>
</head>
<body>
67
<script type="text/javascript">
function Display()
{
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
xmlhttp.open("GET","UserInfo.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var x=xmlDoc.getElementsByTagName("PersonDetails");
var key_id=document.getElementById("key").value;
for(i=0;i<x.length;i++)
{
if(key_id.match(x[i].getElementsByTagName("id")[0].childNodes[0].nodeValue))
j=i;
}
document.write("<h3>User Details are...</h3> <hr> Registeration ID=");
document.write(x[j].getElementsByTagName("id")[0].childNodes[0].nodeValue);
document.write("</br> Name=");
document.write(x[j].getElementsByTagName("name")[0].childNodes[0].nodeValu
e);
document.write("</br> City=");
68
document.write(x[j].getElementsByTagName("city")[0].childNodes[0].nodeValue)
;
document.write("</br> Branch=");
document.write(x[j].getElementsByTagName("Branch")[0].childNodes[0].nodeVa
lue);
document.write("</br> Year=");
document.write(x[j].getElementsByTagName("Year")[0].childNodes[0].nodeValu
e);
document.write("</br> ");
}
</script>
<form name='myform'>
Enter ID:
<input type='text' id='key'/><br/>
<input type='button' value='submit' onclick='Display()'/>
</form>
</body>
</html>
69
OUTPUT:
RESULT:
Thus the Program takes user id as an input and returns the user details by
taking the user information from the XML document has been executed
successfully.
70
EX.NO:9.A
AIM:
To Implement a simple web application using Spring.
PROCEDURE:
CODING:
STUDENT.JSP
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<center>
71
<h1>${Heading}</h1>
Roll Number ${r}
<br>
Name ${n}
<br>
Course ${c}
<br>
</center>
</body>
</html>
INDEX.JSP
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome to Spring Web MVC project</title>
</head>
<body>
<p>Hello! This is the default welcome page for a Spring Web MVC
project.</p>
<p><i>To display a different welcome page for this project, modify</i>
<tt>index.jsp</tt> <i>, or create your own welcome page then change
72
the redirection in</i> <tt>redirect.jsp</tt> <i>to point to the new
welcome page and also update the welcome-file setting in</i>
<tt>web.xml</tt>.</p>
<a href="student.htm">Student Page</a>
</body>
</html>
DISPATCHER-SERVELET.XML
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<center>
<h1>${Heading}</h1>
Roll Number ${r}
<br>
Name ${n}
<br>
Course ${c}
<br>
</center>
</body>
</html>
73
StudentController.java
package controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
/**
*
* @author Mca
*/
public class StudentController extends AbstractController {
public StudentController() {
}
74
return mv;
}
OUTPUT:
75
RESULT:
Thus a simple web MVC application using the Spring Framework has been
executed successfully.
76
EX.NO:9.B
AIM:
To implement a spring MVC with mysql.
PROCEDURE:
CODING:
Index.jsp:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome to Spring Web MVC project</title>
</head>
<body>
77
<p>Hello! This is the default welcome page for a Spring Web MVC
project.</p>
<p><i>To display a different welcome page for this project, modify</i>
<tt>index.jsp</tt> <i>, or create your own welcome page then change
the redirection in</i> <tt>redirect.jsp</tt> <i>to point to the new
welcome page and also update the welcome-file setting in</i>
<tt>web.xml</tt>.</p>
<a href="student.htm">Student Page</a>
<br>
<br>
<a href="employee.htm">Employee Page</a>
</body>
</html>
Employee.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Employee</title>
</head>
<body>
<center>
<h1>Employee List</h1>
<form method="post">
78
ID <input type="text" name="t1"/><br><br>
Name <input type="text" name="t2"/><br><br>
Salary <input type="text" name="t3"/><br><br>
<input type="submit" name="submit" value="Save"/>
<br>
${msg}
<hr>
<!--
<h1>Employee List</h1>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Salary</th>
</tr>
</table>
-->
</form>
</center>
</body>
</html>
79
Dispatcherservlet.xml:
<?xml version='1.0' encoding='UTF-8' ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<bean
class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandle
rMapping"/>
<bean class="controller.StudentController"></bean>
<bean class="controller.EmployeeController"></bean>
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="index.htm">indexController</prop>
80
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="index" />
</beans>
EmployeeController.java:
package controller;
import java.sql.Connection;
import javax.sql.*;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.List;
81
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import model.employee;
public EmployeeController() {
}
if(request.getParameter("submit")!=null)
{
String id=request.getParameter("t1");
String na=request.getParameter("t2");
String sal=request.getParameter("t3");
model.employee ob=new model.employee();
ob.setId(Integer.parseInt(id));
ob.setName(na);
82
ob.setSalary(Integer.parseInt(sal));
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?zeroDate
TimeBehavior=convertToNull","root","");
Statement st=con.createStatement();
String qry="insert into employee
values('"+ob.getId()+"','"+ob.getName()+"','"+ob.getSalary()+"')";
int rs=st.executeUpdate(qry);
if(rs>0)
{
mv.addObject("msg", "Save Successfully");
}
catch(Exception e)
{
mv.addObject("msg", "Error"+e);
}
83
return mv;
Employee.java:
package model;
int id;
String name;
int salary;
public employee() {
}
84
return id;
}
85
OUTPUT:
RESULT:
Thus, the above program has been executed successfully.
86
EX.NO:10
JPA
DATE:14.07.2022
AIM
To create a web application using the JPA.
PROCEDURE:
STEP 1: Creating the Web Application project.
STEP 2: Connect the sample database in services tab.
STEP 3: Creating a database in persistance menu.
STEP 4: Add column from the sample database. Create entity class a
model package.
STEP 5: Create JSF Pages from entity classes. Add all columns in entity class.
STEP 6: Create a “controller” session bean package and “view” JSF Page folder
STEP 7: Run the project.
87
PROGRAM:
88
89
90
91
92
93
94
95
96
97
98
OUTPUT:
99
100
RESULT:
Thus the implementation of Web Application Using Hibernate executed
successfully.
101