0% found this document useful (0 votes)
196 views65 pages

CS8661 - IP - LAB - MANUAL (1) (Repaired)

The document outlines a lab manual for an Internet Programming course. It contains 15 programming tasks covering topics like creating web pages with HTML, using cascading style sheets, validating forms with JavaScript, creating dynamic web pages with servlets and JSP, and more. The tasks are divided into three sections and include creating a web page with an embedded map and hotspots, creating pages using different stylesheets, and validating forms using JavaScript. Students would complete the tasks to learn about web development technologies and their applications. Assessment is based on task completion, with marks awarded for each completed task and additional marks for overall assessment.

Uploaded by

CINDURASRI T L
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
196 views65 pages

CS8661 - IP - LAB - MANUAL (1) (Repaired)

The document outlines a lab manual for an Internet Programming course. It contains 15 programming tasks covering topics like creating web pages with HTML, using cascading style sheets, validating forms with JavaScript, creating dynamic web pages with servlets and JSP, and more. The tasks are divided into three sections and include creating a web page with an embedded map and hotspots, creating pages using different stylesheets, and validating forms using JavaScript. Students would complete the tasks to learn about web development technologies and their applications. Assessment is based on task completion, with marks awarded for each completed task and additional marks for overall assessment.

Uploaded by

CINDURASRI T L
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 65

DEPARTMENT OF COMPUTER SCIENCE &

ENGINEERING

LAB MANUAL

III YEAR BATCH : 2020-2024

INTERNET PROGRAMMING LAB (CS8661)

INDEX
CY MARKS SIGNA

S.NO TITLE PAGE NO.

CLE (25) TURE

CS8661 INTERNET PROGRAMMING LABORATORY


1 DEPT OF CSE /
1 Create a web page with the following using HTML
a. To embed a map in a web page
b. To fix the hot spots in that map
c. Show all the related information when the hot spots are clicked

2 Create a web page with the following.


I
a. Cascading style sheets.
b. Embedded style sheets.
Use our college information for the web pages.

3 Validate the Registration, user login, user profile and payment by credit card pages using
JavaScript

4 Write programs in Java using Servlets:


i. To invoke servlets from HTML forms
ii. To invoke servlets from Applets

5 Write programs in Java to create three-tier applications using servlets for conducting on-

line examination for displaying student mark list. Assume that student information is

II available in a database which has been stored in a database server.

6 Install TOMCAT web server. Convert the static webpages of programs 1&2 into dynamic

web pages using servlets (or JSP) and cookies. Hint: Users information (user id, password,

credit card number) would be stored in web.xml. Each user should have a separate

Shopping Cart.

7 Redo the previous task using JSP by converting the static web pages into dynamic web
pages. Create a database with user information and books information. The books
catalogue should be dynamically loaded from the database

8
Create and save an XML document at the server, which contains 10 users Information.
Write a Program, which takes user Id as an input and returns the User details by taking
III
the user information from the XML document

9 Validate the form using PHP regular expression.

10 Write a web services for finding what people think by asking 500 people’s opinion for any
consumer product

ASSESSMENT

11 I Inline style sheets.

12 II Write programs in Java using Servlets:


Session tracking using hidden form fields and Session tracking for a hit count

13 III PHP stores a form data into database.

CONTENT BEYOND THE SYLLABUS

14 Develop an applet that receives an integer in one text field, and computes its factorial

Value and returns it in another text field, when the button named “Compute” is clicked.

CS8661 INTERNET PROGRAMMING LABORATORY


2 DEPT OF CSE /
15 Write an HTML page including any required java script that breaks a number from one

text field in a range of 0 to 999 and shows it in another text field in words.if the number is

out of range it should show “out of range” and if it is not a number it should show “not a

number”, in the result box.

Program Completion (25)

Assessment marks (15)

TOTAL MARKS (40)

1. WEB PAGE INCLUDING MAP AND FIXING HOTSPOTS


AIM:

• To create a webpage with the following using HTML


• To embed an image in web page
• To fix the hot spots.
• Show all the related information when a hot spot is clicked in the map

PROGRAM:

Index home page:

<html>
<body>

<p>
<map name="imap">

<area href="delhi.html" shape="circle" coords="459,132,16,12">


<area href="chennai.html" shape="circle" coords="380,475,14,12">

</map>
<img border="0" src="imap.gif" usemap="imap" width="962" height="620">

</p>
</body>

</html>

CS8661 INTERNET PROGRAMMING LABORATORY


3 DEPT OF CSE /
Delhi web page:

<html>
<head>

<title>DELHI</title>
</head>

<body bgcolor="lavender">

<p align="center"><font face="arial" color="magenta" size="4">


<b><i><u><marquee>Welcome to DELHI</marquee></u></i></b>

</font></p>
<p align="left">

<font face="times new roman" color="red" size="4">


<b><u><i>About DELHI:</b></u></i>

</font>
</p>

Delhi is the capital of INDIA. It is one of the metropolitan cities in INDIA. It is the ancient and advanced city.
Indian politics is mainly concentrates in this city.The Supreme court and defense headquarters are located in the city.

</font>
</p>

<p align="left"><font face="times new roman" color="red" size="4">


<b><u><i>Important places:</b></u></i>

</font></p>
<p align="left">

<font face="times new roman" color="blue" size="3">


1.India Gate<br>2.Taj Mahal<br>3.Ancient Buildings

</font></p>
</body>

</html>
Chennai web page:
<html>
<head>

<title>CHENNAI</title>
</head>

<body>
</head>

<body bgcolor="lavender">
<p align="center"><font face="arial" color="magenta" size="4">

<b><i><u><marquee>Welcome to CHENNAI</marquee></u>
</i></b></font></p>

<p align="left"><font face="times new roman" color="red" size="4">


<b><u><i>About CHENNAI:</b></u></i>

</font></p>
<p align="left"><font face="times new roman" color="blue" size="4">

CS8661 INTERNET PROGRAMMING LABORATORY


4 DEPT OF CSE /
Chennai is the capital of the state Tamil Nadu.
It is one of the metropolitan cities in INDIA. It ranks 4th best city in INDIA.

The city has International airport as wll as world's second beach <b> MARINA</b>.It has IT industry focus today.

</font></p>
<p align="left"><font face="times new roman" color="red" size="4">
<b><u><i>Important places:</b></u></i>
</font></p>

<p align="left">
<font face="times new roman" color="blue" size="3">

1.Marina Beach<br>2.Satyam Theater<br>3.Express Avenue


</font></p>

</body>
</html>
OUTPUT 1: OUTPUT 2:
Index Home page:

RESULT:

2. WEB PAGE CREATION USING STYLE SHEETS


AIM:
To create a webpage with the following using html to embedded the style sheet

INLINE.html

<html>
<head>

CS8661 INTERNET PROGRAMMING LABORATORY


5 DEPT OF CSE /
<title> inline styles </title>
</head>

<body>
<p>this text doesn't have any style applied to it </p>

<p style="font-size :40pt">the style is applied to <t>"JEPPIAAR"</t>text</p>


<p style="font-size :15pt;color:red">

this text has been formated</p>


</body>

</html>
EXTERNAL.html

<html>
<head>

<title>linking to External style sheet</title>


<link rel="stylesheet"type="text/css"href="style.css"/>

</head>
<body>

<h1>Jeppiaar Engineering<em>College</em>:</h1>
<h2>Computer Science Engineering</h2>

<ul>
<li>Departments
<ul>

<li>CSE</li>
<li>IT</li>

<li>MCA</li>
</ul>

</li>
<li>ECE</li>

<li>EEE</li>
</ul>
<p><a class="nodec" href="http:\\www.jeppiaarcollege.org">Go to Jeppiaar website</a></p>
</body>

</html>
style.css:

BODY{background-color:green;font-family:sans-serif}
CAPTION{font-size:large;font-weight:bold}

H1{font-family:helvetica;color:blue}
H2{font-family:arial;color:red}

EMBEDDED.html:
<html>

<head>
<style type="text/css">

p.one
{

CS8661 INTERNET PROGRAMMING LABORATORY


6 DEPT OF CSE /
border-style:solid;
border-color:#00ff00

}
p.two

{
border-style:solid;

border-color:red blue
}

p.three
{

border-style:solid;
border-color:red blue green

}
p.four

{
border-style:solid;

border-color:red blue green


rgb(250,0,255)

}
</style></head></body>

<p class="one"><b>Note:</b>our college has 8 branches</p>


<p class="two"><b>Note:</b>our college has 8 branches</p>

<p class="three"><b>Note:</b>our college has 8 branches</p>


<p class="four"><b>Note:</b>our college has 8 branches</p>

</body></html>
<html>

<head>
<style type="text/css">

body{background-color:cyan}
h1{background-color:#00ff00}

h2{background-color:transparent}
p{background-color:rgb(250,0,250)}

</style>
<head>

<body>
<h1>JEC</h1>

<h2>Chennai</h2>
<p>this is a reputed college in TN</p>

<br>this college has sister institution


<br>name:Satyabama University

</body></html>

CS8661 INTERNET PROGRAMMING LABORATORY


7 DEPT OF CSE /
OUTPUT:
EMBEDDED.html EXTERNAL.html
INLINE .html

RESULT:

3. VALIDATION USING JAVASCRIPT

AIM: Validate the Registration, user login, user profile and payment by credit card pages using JavaScript.

PROCEDURE:

• Home page:
Main.html:

<frameset rows=”25%, 75 %”>


<frame src=”top.html” name=”top”>

<frameset cols=”25%,75%”>
<frame src=”left.html” name=”left”>

<frame src=”right.html” name=”right”>


</frameset>

</frameset>
Top.html:

<html>
<body bgcolor=”pink”>

<br><br>

CS8661 INTERNET PROGRAMMING LABORATORY


8 DEPT OF CSE /
<marquee><h1 align=”center”><b><u>ONLINE BOOK
STORAGE</u></b></h1></marquee>

</body>
</html>

Right.html:
<html>

<body bgcolor=”pink”>
<br><br><br><br><br>

<h2 align=”center”>
<b><p> welcome to online book storage. Press login if you are having id otherwise press registration.

</p></b></h2>
</body></html>

Left.html:
<html>

<body bgcolor=”pink”>
<h3>

<ul>
<li><a href=”login.html” target=”right”><font color=”black”> LOGIN</font></a></li><br><br>

<li><a href=”profile.html” target=”right”><fontcolor=”black”> USER PROFILE</font></a></li><br>


<br>

<li><a href=”catalog.html” target=”right”><fontcolor=”black”> BOOKS CATALOG</font></a></li>


<br><br>

<li><a href=”scart.html” target=”right”><font color=”black”> SHOPPINGCART</font></a></li><br>


<br>

<li><a href=”payment.html” target=”right”><fontcolor=”black”> PAYMENT</font></a></li><br><br>


<li><a href=”order.html” target=”right”><font color=”black”> ORDER CONFIRMATION</font></a>

</li><br><br>
</ul>

</body>
</html>

Registration and user Login


Login.html:

<html>
<body bgcolor="pink"><br><br><br>

<script language="javascript">
function validate()

{
var flag=1;

if(document.myform.id.value==""||
document.myform.pwd.value=="")

{
flag=0;

CS8661 INTERNET PROGRAMMING LABORATORY


9 DEPT OF CSE /
if(flag==1)
{

alert("VALID INPUT");
}

else
{

alert("INVALID INPUT");
document.myform.focus();

}
}

</script>
<form name="myform">

<div align="center"><pre>
LOGIN ID :<input type="text" name="id"><br> PASSWORD:<input type="password" name="pwd">

</pre><br><br>
</div>

<br><br>
<div align="center">

<input type="submit" value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;


<input type="reset" value="clear" >

</form>
</body>

</html>

user profile page

Profile.html:
<html>

<body bgcolor=”pink”><br><br>
<script language=”javascript”>

function validate()
{

var flag=1;
if(document.myform.name.value==””||

document.myform.addr.value==””||
document.myform.phno.value==””||

document.myform.id.value==””||
document.myform.pwd.value==””)

{
flag=0;

}
var str=document.myform.phno.value;

var x;

CS8661 INTERNET PROGRAMMING LABORATORY


10 DEPT OF CSE /
for(var i=0;i<str.length;i++)
{

x=str.substr(i,1)
if(!(x<=9))

{
flag=0;

break;
}

}
if(flag==1)

{
alert("VALID INPUT");

}
else

{
alert("INVALID INPUT");

document.myform.focus();
}}

</script>
<form name="myform">

<div align="center"><pre>
NAME :<input type="text" name="name"><br> ADDRESS :<input type="type" name="addr"><br>

CONTACT NUMBER:<iput type="text" name="phno"><br> LOGINID :<input type="text" name="id">


<br> 19

PASSWORD :<input type="password" name="pwd"></pre><br><br>


</div>

<br><br>
<div align="center">

<input type="submit" value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;


<input type="reset" value="clear">

</form></body></html>
Books catalog :

Scart.html:
<html>

<body bgcolor="pink"><br><br><br>
<script language="javascript">

function validate()
{

var flag=1;
if(document.myform.title.value=="")

{
flag=0;

CS8661 INTERNET PROGRAMMING LABORATORY


11 DEPT OF CSE /
str=document.myform.title.value;
if(str=="c")

{
document.writeln("<body bgcolor=pink>");

document.writeln("title-->c"+" cost-->444");
}

else if(str=="jsp")
{

document.writeln("<body bgcolor=pink>");
document.writeln("title-->jsp"+" cost-->555");

}
else

{
flag=0;

}
if(flag==1)

{
alert("VALID INPUT");

}
else

{
alert("INVALID INPUT");

document.myform.focus();
}

}
</script>

<form name="myform" >


<div align="center"><pre>

BOOK TITLE :<input type="text" name="title"><br> 21


</pre><br><br>

</div>
<br><br>

<div align="center">
<input type="submit" value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;

<input type="reset" value="clear">


</form>

</body>
</html>

Shopping cart:

Catalog.html:
<html>

<body bgcolor="pink"><br><br><br>

CS8661 INTERNET PROGRAMMING LABORATORY


12 DEPT OF CSE /
<script language="javascript">
function validate()

{
var flag=1;

if(document.myform.id.value==""||
document.myform.title.value==""||

document.myform.no.value==""||
document.myform.cost.value==""||

document.myform.date.value=="")
{

flag=0;
}

var str=document.myform.no.value;
var x;

for(var i=0;i<str.length;i++)
{

x=str.substr(i,1)
if(!(x<=9))

{
flag=0;

break;
}

}
str=document.myform.title.value;

var str1=document.myform.cost.value;
if(!((str=="c"&& str1==444) || (str=="jsp" && str1==555)))

{
flag=0;

}
if(flag==1)

{
alert("VALID INPUT");

}
else

{
alert("INVALID INPUT");

document.myform.focus();
}

}
</script>

<form name="myform" >


<div align="center"><pre>

LOGIN ID :<input type="text" name="id"><br> TITLE :<input type="text" name="title"><br> NO.OF

CS8661 INTERNET PROGRAMMING LABORATORY


13 DEPT OF CSE /
BOOKS
:<input type="text" name="no"><br>

COST OF BOOK
:<input type="text"name="cost"><br>

DATE :<input type="text" name="date"><br></pre><br><br>


</div>

<br><br>
<div align="center">

<input type="submit" value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;


<input type="reset" value="clear">

</form>
</body>

</html>
Payment by credit card

Payment.html:
<html>

<body bgcolor="pink"><br><br><br>
<script language="javascript">

function validate()
{

var flag=1;
if(document.myform.id.value==""||

document.myform.pwd.value==""||
document.myform.amount.value==""||

document.myform.num.value=="")
{

flag=0;
}

var str=document.myform.amount.value;
var x;

for(var i=0;i<str.length;i++)
{

x=str.substr(i,1);
if(!(x<=9))

{
flag=0;

break;
}

}
str=document.myform.num.value;

for(var i=0;i<str.length;i++)
{

x=str.substr(i,1);

CS8661 INTERNET PROGRAMMING LABORATORY


14 DEPT OF CSE /
if(!(x<=9))
{

flag=0;
break;

}
}

if(flag==1)
{

alert("VALID INPUT");
}

else
{

alert("INVALID INPUT");
document.myform.focus();

}
}

</script>
<form name="myform">

<div align="center"><pre>
LOGIN ID :<input type="text" name="id"><br> PASSWORD :<input type="password" name="pwd">

<br> AMOUNT :<input type="text" name="amount"><br> CREDITCARDNUMBER:<input


type="PASSWORD"

name="num+"><br></pre><br><br>
</div>

<br><br>
<div align="center">

<input type="submit" value="ok" onClick="validate()">&nbsp;&nbsp;&nbsp;&nbsp;


<input type="reset" value="clear" >

</form>
</body>

</html>
Order Confirmation

Order.html:
<html>

<head><title>order conformation</title><M/head>
<body bgcolor="cyan">

<center>
<h1><b>AMAZON</h1>

<pre><strong>
<b>Your order Is Conformed

</strong></pre>
<h2><b>THANK YOU</h2>

</center>

CS8661 INTERNET PROGRAMMING LABORATORY


15 DEPT OF CSE /
</body>
</html>M

OUTPUT:

RESULT:

4 i). INVOKING SERVLETS FROM HTML


FORMS

AIM:
To write a html program for invoking servlet using html.
PROGRAM:

HTML Form:

<html>
<head>

<title>Ordering Pen</title>
<body>

<form name=order action="http://localhost:8080/servlet/sayhello" method=POST>


<input type=radio name=cost value=10>Big<br>

<input type=radio name=cost value=7>Medium<br>


<input type=radio name=cost value=5>Small<br>

Quantity<input type=textField name=quant><br>


Item<input type=textField name=item><br>

CS8661 INTERNET PROGRAMMING LABORATORY


16 DEPT OF CSE /
<input type=Submit name=submit value=Submit>
</form>

</body>
</html>

Servlet Code:
import javax.servlet.*;

import javax.servlet.http.*;
import java.io.*;

public class myForm extends HttpServlet{


public void doPost(HttpServletRequest request,HttpServletResponse response){

PrintWriter out;
int cost=Integer.parseInt(request.getParameter("cost"));

int quant=Integer.parseInt(request.getParameter("quant"));
String m=request.getParameter("item");

try{
out=response.getWriter();

out.println("<html><head><title>Order</title></head><body>");
out.println("Your Order for "+m+" of cost "+cost+" is accepted. Your total Bill is Rs."+cost*quant+".");

out.println("</body></html>");
}

catch(Exception e){}
}

OUTPUT 1: OUTPUT 2:
After submitting:

CS8661 INTERNET PROGRAMMING LABORATORY


17 DEPT OF CSE /
RESULT:

4 ii). INVOKING SERVLETS FROM APPLETS

AIM:
To write a html program for invoking servlet from applet.

PROGRAM:
Invoke.html:

<html>
<head>

<title>hai</title>
</head>

<body>
<applet code="invokeHyp" width="450" height="400">

</applet>
</body>

</html>

invokeHyp.java:
import java.awt.*;

import java.awt.event.*;
import java.applet.*;

import java.net.*;
public class invokeHyp extends Applet implements ActionListener

{
String msg=" ";

Button submit,reset;
Label lbl1=new Label("Enter Quantity:");

Label lbl2=new Label("Enter Item Name:");


TextField item=new TextField();

TextField quant=new TextField();


public void init()

{
submit=new Button("submit");

reset=new Button("reset");
add(lbl2);

add(item);
add(lbl1);

add(quant);
add(submit);

CS8661 INTERNET PROGRAMMING LABORATORY


18 DEPT OF CSE /
add(reset);
submit.addActionListener(this);

reset.addActionListener(this);
}

public void actionPerformed(ActionEvent ae)


{

String str=ae.getActionCommand();
if(str.equals("submit"))

{
msg="Submit";

try
{

System.out.println("Hai");
URL myurl=new

URL("http://localhost:8080/servlet/sayhello?item="+item.getText()+"&quant="+quant.getText());

getAppletContext().showDocument(myurl);
}

catch(Exception e)
{

msg=e.toString();
}

}
else if(str.equals("reset"))

{
msg="Reset";

}
repaint();

}
public void paint(Graphics g)

{
g.drawString(msg,6,200);

}
}

myName.java:
import javax.servlet.*;

import javax.servlet.http.*;
import java.io.*;

public class myName extends HttpServlet


{

public void doGet(HttpServletRequest request,HttpServletResponse response)


{

PrintWriter out;

CS8661 INTERNET PROGRAMMING LABORATORY


19 DEPT OF CSE /
int quant=Integer.parseInt(request.getParameter("quant"));

String myItem=request.getParameter("item");
try

{
out=response.getWriter();

out.println("<HTML><HEAD><TITLE>order</TITLE></HEAD><BODY>");
out.println("Your order for"+quant+" number of" +myItem+" is accepted.");

out.println("</BODY></HTML>");
}

catch(Exception e)
{System.out.println(e);
}}}

OUTPUT:
APPLET VIEWER AFTER SUBMITTING:

OUTPUT 2:

CS8661 INTERNET PROGRAMMING LABORATORY


20 DEPT OF CSE /
RESULT:

5. ONLINE EXAMINATION
AIM:

To write programs in Java to create three-tier applications using servlets for conducting on-line examination for displaying student mark list. Assume that
student information is available in a database which has been stored in a database server.

SERVLET CODE:

import java.io.*;
import java.sql.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class StudentServlet3 extends HttpServlet


{

String message,Seat_no,Name,ans1,ans2,ans3,ans4,ans5;
int Total=0;

Connection connect;
Statement stmt=null;

ResultSet rs=null;
public void doPost(HttpServletRequest request,HttpServletResponse

response) throws ServletException,IOException


{
try
{

String url="jdbc:odbc:NEO";
Class.forNam("sun.jdbc.odbc.JdbcOdbcDriver");

connect=DriverManager.getConnection(url," "," ");


message="Thank you for participating in online Exam";

}
catch(ClassNotFoundException cnfex){

cnfex.printStackTrace();
}

catch(SQLException sqlex)
{ system.out.println(e);

CS8661 INTERNET PROGRAMMING LABORATORY


21 DEPT OF CSE /
catch(Exception excp)
{ system.out.println(e);}

Seat_no=request.getParameter("Seat_no");
Name=request.getParameter("Name");

ans1=request.getParameter("group1");
ans2=request.getParameter("group2");

ans3=request.getParameter("group3");
ans4=request.getParameter("group4");

ans5=request.getParameter("group5");
if(ans1.equals("True"))

Total+=2;
if(ans2.equals("False"))

Total+=2;
if(ans3.equals("True"))

Total+=2;
if(ans4.equals("False"))

Total+=2;
if(ans5.equals("False"))

Total+=2;
try

{
Statement stmt=connect.createStatement();

String query="INSERT INTO student("+"Seat_no,Name,Total"+") VALUES('"+Seat_no+"','"+Name+"','"+Total+"')";


int result=stmt.executeUpdate(query); stmt.close();

}catch(SQLException ex){
}

response.setContentType("text/html");
PrintWriter out=response.getWriter();

out.println("<html>");
out.println("<head>");

out.println("</head>");
out.println("<body bgcolor=cyan>");

out.println("<center>"); out.println("<h1>"+message+"</h1>\n");
out.println("<h3>Yours results stored in our database</h3>");

out.print("<br><br>");
out.println("<b>"+"Participants and their Marks"+"</b>");

out.println("<table border=5>");
try

{
Statement stmt=connect.createStatement(); String query="SELECT *

FROM student"; rs=stmt.executeQuery(query);


out.println("<th>"+"Seat_no"+"</th>");

out.println("<th>"+"Name"+"</th>");

CS8661 INTERNET PROGRAMMING LABORATORY


22 DEPT OF CSE /
out.println("<th>"+"Marks"+"</th>");
while(rs.next())

{
out.println("<tr>");

out.print("<td>"+rs.getInt(1)+"</td>");
out.print("<td>"+rs.getString(2)+"</td>");

out.print("<td>"+rs.getString(3)+"</td>");
out.println("</tr>");

}
out.println("</table>");

}
catch(SQLException ex){ } finally

{
try

{
if(rs!=null)

rs.close();
if(stmt!=null)

stmt.close();
if(connect!=null)

connect.close();
}

catch(SQLException e){ }
}

out.println("</center>");
out.println("</body></html>");

Total=0; } }
HTML CODE:

<html>
<head>

<title>Database Test</title>
</head>

<body>
<center>

<h1>Online Examination</h1>
</ceter>

<form action="://localhost:8080/servlet/sayhello " method="POST"><div align="left"><br></div>


<b>Seat Number:</b><input type="text" name="Seat_no"><div align="Right">

<b>Name:</b><input type="text" name="Name" size="50"><br></div>


<b>1. Every host implements transport layer.</b><br/>

<input type="radio" name="group1" value="True">True


<input type="radio" name="group1" value="False">False<br>

<b>2. It is a network layer's responsibility to forward packets reliably from source to destina-tion</b><br/>

CS8661 INTERNET PROGRAMMING LABORATORY


23 DEPT OF CSE /
<input type="radio" name="group2" value="True">True
<input type="radio" name="group2" value="False">False<br>

<b>3. Packet switching is more useful in bursty traffic</b><br/>


<input type="radio" name="group3" value="True">True

<input type="radio" name="group3" value="False">False<br>


<b>4. A phone network uses packet switching</b>

<br/><input type="radio" name="group4" value="True">True


<input type="radio" name="group4" value="False">False<br>

<b>5. HTML is a Protocol for describing web contents</b>


<input type="radio" name="group5" value="True">True

<input type="radio" name="group5" value="False">False<br><br>


<center>

<input type="submit" value="Submit"><br><br></center>


</form>

</body>
</html>

OUTPUT 1: OUTPUT 2:

AFTER SUBMITTING

RESULT

6. TOMCAT RUNNING PROCEDURE


Content of web.xml:

<servlet>
<servlet_name>any name</servlet_name>
<servlet_class>myform</servlet_class>
</servlet>
<servlet_mapping>
<servlet_name>any name</servlet_name>

CS8661 INTERNET PROGRAMMING LABORATORY


24 DEPT OF CSE /
<url_pattern>/sayhello</url_pattern>//any name different from servlet name
</servlet_mapping>

Start tomcat:

1. Start tomcat startup


2. Goto the Internet Explorer type,
http://localhost:8080/servlet/html file

CREATING DATABASE
1)
Control panel-> Administrative Tools-> Data Sources(ODBC)
-->System DSN-->add (Microsoft Access Driver(*.mdb)🡪finish
🡪 add name ( give database name)

2)
Open Microsoft Access 🡪 create new database(give same database name)
🡪add table 🡪insert fields and values

SHOPPING CART
AIM:
Install TOMCAT web server. Convert the static webpages of assignments 2 into dynamic webpages using servlets and cookies. Hint: Users information (user id,
password,credit card number) would be stored in web.xml. Each user should have a separate Shopping Cart.
Main.html:
<html>
<body>
<br /><br /><br /><br /><br />
<h1 align="center"><U>ONLINE BOOK STORAGE</U></h1><br /><br /><br />
<h2 align="center"><pre>
<b>Welcome to online book storage.
Press LOGIN if you are having id
otherwise press REGISTRATION
</b></pre></h2>
<br /><br /><pre>
<div align="center"><a href="login.html">LOGIN</a><a href="reg.html"> REGISTRATION</a></div>
</pre>
</body>
</html>

Login page:
Login.html:
<html>
<body><br /><br /><br />
<form name="myform" method="post" action="login">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br /> PASSWORD :<input type="password" name="pwd"
/></pre><br /><br />
</div>
<br /><br />

CS8661 INTERNET PROGRAMMING LABORATORY


25 DEPT OF CSE /
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
Registration page:
Reg.html:
<html>
<body><br /><br />
<form name="myform" method="post" action="reg">
<table align="center" >
<tr>
<td>NAME</td>
<td>:<input type="text" name="name" /></td>
</tr>
<tr>
<td>ADDRESS</td>
<td>:<input type="text" name="addr" /></td>
</tr>
<tr>
<td>CONTACT NUMBER</td>
<td>:<input type="text" name="phno" /></td>
</tr>
<tr>
<td>LOGINID</td>
<td>:<input type="text" name="id" /></td>
</tr>
<tr>
<td>PASSWORD</td>
<td>:<input type="password" name="pwd" /></td>
</tr>
</table>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
User profile page:
Profile.html:
<html>
<body><br /><br /><br />
<form name="myform" method="post" action="profile">

CS8661 INTERNET PROGRAMMING LABORATORY


26 DEPT OF CSE /
<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br />
</pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
Books catalog page:
Catalog.html:
<html>
<body><br /><br /><br />
<form method="post" action="catalog">
<div align="center"><pre>
BOOK TITLE :<input type="text" name="title" /><br />
</pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok"
name="button1"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear" name="button2"/>
</div>
</form>
</body>
</html>
Shopping cart, Payment by credit card, Order
Conformation page:
Order.html:
<html>
<body><br /><br />
<form method="post" action="order">
<div align="center"><pre>
ID
:<input type="text" name="id" /><br />
PASSWORD
:<input type="password" name="pwd" /><br/> TITLE
:<input type="text" name="title" /><br /> NO. OF BOOKS
:<input type="text" name="no" /><br />
DATE
:<input type="text" name="date" /><br />
CREDIT CARD NUMBER :<input type="password" name="cno" /><br /></pre><br
/><br />

CS8661 INTERNET PROGRAMMING LABORATORY


27 DEPT OF CSE /
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" name="button1"/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear"
name="button2"/>
</div>
</form></body></html>
Login servlet :
Login.java:
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class login extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body>");
String id=req.getParameter("id");
String pwd=req.getParameter("pwd");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger
");
Statement stmt=con.createStatement();
String sqlstmt="select id,pwd from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
if(id.equals(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==0)
{
pw.println("<br><br>SORRY INVALID ID TRY AGAIN
ID<br><br>");
pw.println("<a href=\"login.html\">press LOGIN to
RETRY</a>");
}

CS8661 INTERNET PROGRAMMING LABORATORY


28 DEPT OF CSE /
else
{
pw.println("<br><br>VALID LOGIN ID<br><br>"); 58
pw.println("<h3><ul>");
pw.println("<li><a
href=\"profile.html\"><fontcolor=\"black\">USER
PROFILE</font>
</a></li><br><br>");
pw.println("<li><a
href=\"catalog.html\"><fontcolor=\"black\">BOOKS
CATALOG</font></a></li><br><br>");
pw.println("<li><a
href=\"order.html\"><fontcolor=\"black\">ORDER
CONFIRMATION</font>
</a></li></ul><br><br>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}
Registration servlet:
Reg.java :
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class reg extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
resp.setContentType("text/html");
pw.println("<html><body>");
String name=req.getParameter("name");
String addr=req.getParameter("addr");
String phno=req.getParameter("phno");
String id1=req.getParameter("id");
String pwd1=req.getParameter("pwd");
int no=Integer.parseInt(phno);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

CS8661 INTERNET PROGRAMMING LABORATORY


29 DEPT OF CSE /
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger
");
Statement stmt=con.createStatement();
String sqlstmt="select id,pwd from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
if(id1.equals(rs.getString(1))&&pwd1.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==1)
{
pw.println("<br><br>SORRY INVALID ID ALREADY
EXITS TRY AGAIN WITH NEW ID<br><br>");
pw.println("<a href=\"reg.html\">press REGISTER to
RETRY</a>");
}
else
{
Statement stmt1=con.createStatement();
stmt1.executeUpdate("insert into login
values('"+name+"','"+addr+"',"+no+",'"+id1+"','"+pwd1+"')
;");
pw.println("<br><br>YOUR DETAILS ARE
ENTERED<br><br>");
pw.println("<a href=\"login.html\">press LOGIN to
login</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}

Profile servlet:
Profile.java:
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

CS8661 INTERNET PROGRAMMING LABORATORY


30 DEPT OF CSE /
public class profile extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body>");
String id=req.getParameter("id");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger
");
Statement stmt=con.createStatement();
String sqlstmt="select * from login where id="+id+""; ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
pw.println("<br><br><br>");
while(rs.next())
{
pw.println("<div align=\"center\">");
pw.println("NAME :"+rs.getString(1)+"<br>");
pw.println("ADDRESS
:"+rs.getString(2)+"<br>");
pw.println("PHONE NO
:"+rs.getString(3)+"<br>");
pw.println("</div>");
flag=1;
}
if(flag==0)
{
pw.println("<br><br>SORRY INVALID ID TRY AGAIN
ID<br><br>");
pw.println("<a href=\"profile.html\">press HERE to
RETRY</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}

CS8661 INTERNET PROGRAMMING LABORATORY


31 DEPT OF CSE /
Catalog servlet:
Catalog.java:
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class catalog extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
PrintWriter pw=resp.getWriter();
pw.println("<html><body>");
String title=req.getParameter("title");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger
");
Statement stmt=con.createStatement();
String sqlstmt="select * from book where title=\'"+title+"\'"; ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
pw.println("<div align=\"center\">");
pw.println("TITLE:"+rs.getString(1)+"<br>");
pw.println("AUTHOR :"+rs.getString(2)+"<br>"); pw.println("VERSION :"+rs.getString(3)+"<br>");
pw.println("PUBLISHER :"+rs.getString(4)+"<br>");
pw.println("COST:"+rs.getString(5)+"<br>");
pw.println("</div>");
flag=1;
}
if(flag==0)
{
pw.println("<br><br>SORRY INVALID TITLE TRY
AGAIN <br><br>");
pw.println("<a href=\"catalog.html\">press HERE to
RETRY</a>");
}
pw.println("</body></html>");
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}

CS8661 INTERNET PROGRAMMING LABORATORY


32 DEPT OF CSE /
}
Order servlet:
Order.java:
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class order extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse resp)
throws ServletException,IOException
{
int count;
PrintWriter pw=resp.getWriter();
pw.println("<html><body>");
String id=req.getParameter("id");
String pwd=req.getParameter("pwd");
String title=req.getParameter("title");
String count1=req.getParameter("no");
String date=req.getParameter("date");
String cno=req.getParameter("cno");
try
{
count=Integer.parseInt(count1);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger
");
Statement stmt=con.createStatement();
String sqlstmt="select id,pwd from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0,amount,x;
while(rs.next())
{
if(id.equals(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==0)
{
pw.println("<br><br>SORRY INVALID ID TRY AGAIN
ID<br><br>");
pw.println("<a href= \" order.html \" >press HERE to RETRY</a>");
}
else
{

CS8661 INTERNET PROGRAMMING LABORATORY


33 DEPT OF CSE /
Statement stmt2=con.createStatement();
String s="select cost from book where title=\'"+title+"\'"; ResultSet rs1=stmt2.executeQuery(s);
int flag1=0;
while(rs1.next())
{
flag1=1;
x=Integer.parseInt(rs1.getString(1));
amount=count*x;
pw.println("<br><br>AMOUNT
:"+amount+"<br><br><br><br>");
Statement stmt1=con.createStatement();
stmt1.executeUpdate("insert into details
values('"+id+"','"+title+"',"+amount+",'"+cno+"');"); pw.println("<br>YOUR ORDER has taken<br>");
}
if(flag1==0)
{
pw.println("<br><br><br>SORRY INVALID ID
TRY AGAIN ID<br><br>");
pw.println("<a href=\"order.html\">press HERE to
RETRY</a>");
}
}
pw.println("</body></html>");
con.close();
}
catch(Exception e)
{
resp.sendError(500,e.toString());
}
}
}
Web.xml:
<?xml version="1.0"?>
<web-app >
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>login</servlet-class>
</servlet>
<servlet>
<servlet-name>reg</servlet-name>
<servlet-class>reg</servlet-class>
</servlet>
<servlet>
<servlet-name>profile</servlet-name>
<servlet-class>profile</servlet-class>
</servlet>
<servlet>

CS8661 INTERNET PROGRAMMING LABORATORY


34 DEPT OF CSE /
<servlet-name>order</servlet-name>
<servlet-class>order</servlet-class>
</servlet>
<servlet>
<servlet-name>catalog</servlet-name>
<servlet-class>catalog</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>reg</servlet-name>
<url-pattern>/reg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>profile</servlet-name>
<url-pattern>/profile</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>order</servlet-name>
<url-pattern>/order</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>catalog</servlet-name>
<url-pattern>/catalog</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>main.html</welcome-file></welcome-file-list>
</web-app>
Output:

OUTPUT
Before Submitting

CS8661 INTERNET PROGRAMMING LABORATORY


35 DEPT OF CSE /
RESULT

7. JSP

AIM:
Redo the previous task using JSP by converting the static web pages of assignments 2 into dynamic web pages. Create a database with user information and books
information and books information. The books catalogue should be dynamically loaded from the database. Follow the MVC architecture while doing the website.
PROCEDURE:
1) Create your own directory under tomcat/webapps (e.g. tr1)
2) Copy the html files in tr1
3) Copy the jsp files also into tr1
4) Start tomcat give the following command
Catalina.bat run
At install-dir/bin
5) at I.E give url as http://localhost:8081/tr1/main.html

Home page:
Main.html:
<html>
<body>
<br><br><br><br><br><br>
<h1 align="center"><u>ONLINE BOOK STORAGE</u></h1><br><br><br>
<h2 align="center"><PRE>
<b> Welcome to online book storage.
Press LOGIN if you are having id

CS8661 INTERNET PROGRAMMING LABORATORY


36 DEPT OF CSE /
Otherwise press REGISTRATION
</b></PRE></h2>
<br><br><pre>
<div align="center"><a href="login.html">LOGIN</a>
<a href="reg.html">REGISTRATION</a></div></pre>
</body></html>
Login page:
Login.html:
<html>
<body><br /><br /><br />
<form name="myform" method="post" action="login.jsp">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br /> PASSWORD :<input type="password" name="pwd"
/></pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
Registration page:
Reg.html:
<html>
<body><br /><br />
<form name="myform" method="post" action="reg.jsp">
<table align="center" >
<tr>
<td>NAME</td>
<td>:<input type="text" name="name" /></td>
</tr>
<tr>
<td>ADDRESS</td>
<td>:<input type="text" name="addr" /></td>
</tr>
<tr>
<td>CONTACT NUMBER</td>
<td>:<input type="text" name="phno" /></td>
</tr>
<tr>
<td>LOGINID</td>
<td>:<input type="text" name="id" /></td>
</tr>
<tr>
<td>PASSWORD</td>

CS8661 INTERNET PROGRAMMING LABORATORY


37 DEPT OF CSE /
<td>:<input type="password" name="pwd" /></td>
</tr>
</table>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
User profile page:
Profile.html:
<html>
<body><br /><br /><br />
<form name="myform" method="post" action="profile.jsp">
<div align="center"><pre>
LOGIN ID :<input type="text" name="id" /><br />
</pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" onclick="validate()" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear" />
</div>
</form>
</body>
</html>
Books catalog page:
Catalog.html:
<html>
<body><br /><br /><br />
<form method="post" action="catalog.jsp">
<div align="center"><pre>
BOOK TITLE :<input type="text" name="title" /><br />
</pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok"
name="button1"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="reset" value="clear" name="button2"/>
</div>
</form>
</body> </html>
Shopping cart, Payment by credit card, Order
Conformation page:

CS8661 INTERNET PROGRAMMING LABORATORY


38 DEPT OF CSE /
Order.html:
<html>
<body><br /><br />
<form method="post" action="order.jsp">
<div align="center"><pre>
ID
:<input type="text" name="id" /><br />
PASSWORD
:<input type="password" name="pwd" /><br/> TITLE
:<input type="text" name="title" /><br /> NO. OF BOOKS :<input type="text" name="no" /><br />
DATE
:<input type="text" name="date" /><br />
CREDIT CARD NUMBER :<input type="password" name="cno" /><br
/></pre><br /><br />
</div>
<br /><br />
<div align="center">
<input type="submit" value="ok" name="button1"/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="clear"
name="button2"/>
</div>
</form>
</body>
</html>
Login JSP:
Login.jsp:
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% out.println("<html><body>");
String id=request.getParameter("id");
String pwd=request.getParameter("pwd");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger"); Statement
stmt=con.createStatement();
String sqlstmt="select id,pwd from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
if(id.equals(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==0)
{

CS8661 INTERNET PROGRAMMING LABORATORY


39 DEPT OF CSE /
out.println("<br><br>SORRY INVALID ID TRY AGAIN
ID<br><br>");
out.println("<a href=\"login.html\">press LOGIN to
RETRY</a>");
}
else
{
out.println("<br><br>VALID LOGIN ID<br><br>"); out.println("<h3><ul>");
out.println("<li><a
href=\"profile.html\"><fontcolor=\"black\">USER
PROFILE</font>
</a></li><br><br>");
out.println("<li><a
href=\"catalog.html\"><fontcolor=\"black\">BOOKS
CATALOG</font></a></li><br><br>");
out.println("<li><a
href=\"order.html\"><fontcolor=\"black\">ORDER
CONFIRMATION</font>
</a></li></ul><br><br>");
}
out.println("</body></html>");
con.close();
%>

Registration JSP:
Reg.jsp :
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% response.setContentType("text/html");
out.println("<html><body>");
String name=request.getParameter("name");
String addr=request.getParameter("addr");
String phno=request.getParameter("phno");
String id1=request.getParameter("id");
String pwd1=request.getParameter("pwd");
int no=Integer.parseInt(phno);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger"); Statement
stmt=con.createStatement();
String sqlstmt="select id,pwd from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{ if(id1.equals(rs.getString(1))&&pwd1.equals(rs.getString(2)))
{
flag=1;

CS8661 INTERNET PROGRAMMING LABORATORY


40 DEPT OF CSE /
}
}
if(flag==1)
{ out.println("<br><br>SORRY INVALID ID ALREADY
EXITS TRY AGAIN WITH NEW ID<br><br>");
out.println("<a href=\"reg.html\">press REGISTER to
RETRY</a>");
}
else
{ Statement stmt1=con.createStatement();
stmt1.executeUpdate("insert into login
values('"+name+"','"+addr+"',"+no+",'"+id1+"','"+pwd1+"');"); out.println("<br><br>YOUR DETAILS
ARE
ENTERED<br><br>");
out.println("<a href=\"login.html\">press LOGIN to
login</a>");
}
out.println("</body></html>");
con.close();
%>
Profile JSP:
Profile.jsp:
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% out.println("<html><body>");
String id=request.getParameter("id");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger"); Statement
stmt=con.createStatement();
String sqlstmt="select * from login where id="+id+""; ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
out.println("<br><br><br>");
while(rs.next())
{
out.println("<div align=\"center\">");
out.println("NAME :"+rs.getString(1)+"<br>");
out.println("ADDRESS
:"+rs.getString(2)+"<br>");
out.println("PHONE NO
:"+rs.getString(3)+"<br>");
out.println("</div>");
flag=1;
}
if(flag==0)
{
out.println("<br><br>SORRY INVALID ID TRY AGAIN

CS8661 INTERNET PROGRAMMING LABORATORY


41 DEPT OF CSE /
ID<br><br>");
out.println("<a href=\"profile.html\">press HERE to
RETRY</a>");
}
out.println("</body></html>");
con.close(); %>
Catalog JSP:
Catalog.jsp:
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% out.println("<html><body>");
String title=request.getParameter("title");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger"); Statement
stmt=con.createStatement();
String sqlstmt="select * from book where title=\'"+title+"\'"; ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0;
while(rs.next())
{
out.println("<div align=\"center\">");
out.println("TITLE
:"+rs.getString(1)+"<br>");
out.println("AUTHOR :"+rs.getString(2)+"<br>"); out.println("VERSION :"+rs.getString(3)+"<br>");
out.println("PUBLISHER :"+rs.getString(4)+"<br>"); out.println("COST
:"+rs.getString(5)+"<br>");
out.println("</div>");
flag=1;
}
if(flag==0)
{
out.println("<br><br>SORRY INVALID TITLE TRY
AGAIN <br><br>");
out.println("<a href=\"catalog.html\">press HERE to
RETRY</a>");
}
out.println("</body></html>");
con.close();
%>

Order servlet:
Order.java:
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<% int count;
out.println("<html><body>");
String id=request.getParameter("id");

CS8661 INTERNET PROGRAMMING LABORATORY


42 DEPT OF CSE /
String pwd=request.getParameter("pwd");
String title=request.getParameter("title");
String count1=request.getParameter("no");
String date=request.getParameter("date");
String cno=request.getParameter("cno");
count=Integer.parseInt(count1);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("jdbc:odbc:orcl","scott","tiger"); Statement
stmt=con.createStatement();
String sqlstmt="select id,pwd from login";
ResultSet rs=stmt.executeQuery(sqlstmt);
int flag=0,amount,x;
while(rs.next())
{
if(id.equals(rs.getString(1))&&pwd.equals(rs.getString(2)))
{
flag=1;
}
}
if(flag==0)
{
out.println("<br><br>SORRY INVALID ID TRY AGAIN
ID<br><br>");
out.println("<a href= \"order.html \" >press HERE to RETRY</a>");
}
else
{
Statement stmt2=con.createStatement();
String s="select cost from book where title=\'"+title+"\'"; ResultSet rs1=stmt2.executeQuery(s);
int flag1=0;
while(rs1.next())
{
flag1=1;
x=Integer.parseInt(rs1.getString(1));
amount=count*x;
out.println("<br><br>AMOUNT
:"+amount+"<br><br><br><br>");
Statement stmt1=con.createStatement();
stmt1.executeUpdate("insert into details
values('"+id+"','"+title+"',"+amount+",'"+cno+"');"); out.println("<br>YOUR ORDER has taken<br>");
}
if(flag1==0)
{
out.println("<br><br><br>SORRY INVALID ID
TRY AGAIN ID<br><br>");
out.println("<a href=\"order.html\">press HERE to

CS8661 INTERNET PROGRAMMING LABORATORY


43 DEPT OF CSE /
RETRY</a>");
}
}
out.println("</body></html>");
con.close();
%>
Output:

8. XML
AIM:
Create and Save an XML document at the server, which contains 10 users information. Write program, which takes user ID as input and returns the user details by taking
the user information from XML Document.
Login Page:
Std.html:
<html>
<head>
<script>
function LoadXmlDoc(dname)
{
xmldoc=new ActiveXObject("Microsoft.XMLDOM");
xmldoc.async="false";
xmldoc.load(dname);
return xmldoc;
}
function validate()
{
var i,k,j=0;
xmldoc=LoadXmlDoc("student.xml");
var v1=myform.n2.value;
if(v1.length==0)
window.alert("enter the roll no.");
else
{
v1=parseInt(v1);
arr=xmldoc.getElementsByTagName("students");
for(i=0;i<arr.length;i++)
{
var txt=xmldoc.getElementsByTagName("rollno")[i].childNodes[0].nodeValue; if(txt==v1)
{k=i;
j=1;
}
}
if(j==1)

CS8661 INTERNET PROGRAMMING LABORATORY


44 DEPT OF CSE /
{
nam=xmldoc.getElementsByTagName("name")[k].childNodes[0].nodeValue;
rol=xmldoc.getElementsByTagName("rollno")[k].childNodes[0].nodeValue;
per=xmldoc.getElementsByTagName("percentage")[k].childNodes[0].nodeValue; 47
document.write("<body bgcolor='pink'>");
document.write("<table border=1 align='center'><tr><th colspan='2'>USER
DETAILS</th></tr>");
document.write("<tr><th>Name::</th><td>"+nam+"</td></tr>"); document.write("<tr>
<th>RollNumber::</th><td>"+rol+"</td></tr>"); document.write("<tr><th>Percentage::</th>
<td>"+per+"</td></tr>"); document.write("</table></body>");
}
else
window.alert("roll number not found");
}
}
</script>
</head>
<body bgcolor="pink" text="red">
<form name="myform">
<table align="center">
<tr><td><B>RollNumber</B></td><td><input type="text" size=15
name="n2"></td></tr>
</table>
<br>
<center><input type=submit value="submit" name="b1" onClick="validate()"></center>
</form>
</body>
</html>
Student XML Document:
Student.xml:
<?xml version="1.0" ?>
<cse>
<students>
<rollno>501</rollno>
<name>ABC</name>
<percentage>65%</percentage>
</students>
<students>
<rollno>502</rollno>
<name>DEF</name>
<percentage>67%</percentage>
</students>
<students>
<rollno>503</rollno>
<name>GHI</name>
<percentage>69%</percentage>
</students>

CS8661 INTERNET PROGRAMMING LABORATORY


45 DEPT OF CSE /
<students>
<rollno>504</rollno>
<name>JKL</name>
<percentage>65%</percentage>
</students>
<students>
<rollno>505</rollno>
<name>MNO</name>
<percentage>73%</percentage>
</students>
<students>
<rollno>506</rollno>
<name>PQR</name>
<percentage>74%</percentage>
</students>
<students>
<rollno>507</rollno>
<name>stu</name>
<percentage>65%</percentage>
</students>
<students>
<rollno>508</rollno>
<name>VWX</name>
<percentage>70%</percentage>
</students>
<students>
<rollno>509</rollno>
<name>YZ</name>
<percentage>72%</percentage>
</students>
<students>
<rollno>510</rollno>
<name>PQR</name>
<percentage>75%</percentage>
</students>
</cse>
Output:

CS8661 INTERNET PROGRAMMING LABORATORY


46 DEPT OF CSE /
RESULT:

9. PHP

AIM
To write a program to implement Ajax live search application

ALGORITHM
Step 1: Create the HTML document.
Step 2: Create a HTML form
Step 3: Using the input tag get first name
Step 4: Invoke the script function ShowHint()
Step 5: Check the value of first name with php file content

CS8661 INTERNET PROGRAMMING LABORATORY


47 DEPT OF CSE /
Step 6: Invoke GetHint.php to make a lookup to get suggestions
Step 7: If available, Output will be displayed in the Web Browser instantly.
Step 8: If not, “no suggestion” will be printed

Nosugesstion.html
<!DOCTYPE html>
<html>
<head>
<script>
function showHint(str)
{
if (str.length==0) {
document.getElementById("txtHint").innerHTML="";
return;
} else {
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","gethint.php?q="+str,true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<p><b>Start typing a name in the input field below:</b></p>
<form action="">
First name: <input type="text" id="txt1" onkeyup="showHint(this.value)">
</form>
<p>Suggestions: <span id="txtHint"></span></p>
</body>
</html>

GETHINT.PHP
<?PHP

$A[] = "APPLE";

$A[] = "BABY";

$A[] = "COOL";

$A[] = "KITTY";

$Q = $_REQUEST["Q"];

$HINT = "";

// LOOKUP ALL HINTS FROM ARRAY IF $Q IS DIFFERENT FROM ""

CS8661 INTERNET PROGRAMMING LABORATORY


48 DEPT OF CSE /
IF ($Q !== "") {

$Q = STRTOLOWER($Q);

$LEN=STRLEN($Q);

FOREACH($A AS $NAME) {

IF (STRISTR($Q, SUBSTR($NAME, 0, $LEN))) {

IF ($HINT === "") {

$HINT = $NAME;

} ELSE {

$HINT .= ", $NAME";

// Output "no suggestion" if no hint was found or output correct values

echo $hint === "" ? "no suggestion" : $hint;

?>

Output:

OUTPUT2:

CS8661 INTERNET PROGRAMMING LABORATORY


49 DEPT OF CSE /
RESULT:
10.WEB SERVICES

      a) Connecting a web service with database

To create a Web Service and the connect that web service   to the database using java & also write a WSDL & SOAP code for that web service.

Program:

package db;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jws.WebService;
import javax.jws.WebMethod;
@WebService()
public class NewWebService {

   
   @WebMethod(operationName = "dbcon")
   public String dbcon() {
       //TODO write your implementation code here:
            String s="";
       Connection con;
       String line;
       try {
           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
           con=DriverManager.getConnection("jdbc:odbc:student");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from stud");
           line="<br>";
           while(rs.next())

CS8661 INTERNET PROGRAMMING LABORATORY


50 DEPT OF CSE /
           {
               s += line+"Rollno:" + rs.getString(1) +line;
               s += "Name:" + rs.getString(2) +line;
               s += "Mark1:" +rs.getString(3) +line;
               s += "Mark2:" +rs.getString(4) +line;
               s += "Mark3:" +rs.getString(5) +line+line;
           }
       } catch (Exception ex) {
         Logger.getLogger(NewWebService.class.getName()).log(Level.SEVERE, null, ex);
       }
       //TODO write your implementation code here:

       return s;

   }

OUTPUT:

SOAP Request

<?xml version="1.0" encoding="UTF-8"?>


<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Header/>
   <S:Body>
       <ns2:dbcon xmlns:ns2="http://db/"/>
   </S:Body>
</S:Envelope>

CS8661 INTERNET PROGRAMMING LABORATORY


51 DEPT OF CSE /
SOAP Response

<?xml version="1.0" encoding="UTF-8"?>


<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
       <ns2:dbconResponse xmlns:ns2="http://db/">
           <return><br>Rollno:34555<br>Name:suresh<br>Mark1:90<br>Mark2:50<br>Mark3:60<br><br><br>Rollno:45666<br>Name:ovi<br>Mark1:100<br>Mark2:9
8<br>Mark3:90<br><br><br>Rollno:63440<br>Name:nithin<br>Mark1:70<br>Mark2:80<br>Mark3:75<br><br></return>
       </ns2:dbconResponse>
   </S:Body>
</S:Envelope>

Result:

B.CONSUMING A WEB SERVICE THROUGH AN APPLICATION

Aim:

To create a web service for adding few numbers using NetBeans and write client side code to invoke the web service.

STEPS TO CREATE CLIENT SIDE PROJECT:

1.create the new project as above and give the name as addclient.

2. addclient project will be created. right click it and choose the following.

CS8661 INTERNET PROGRAMMING LABORATORY


52 DEPT OF CSE /
3.Then browse and choose the addweb wsdl file

4.Then choose the following and add the source code in index.jsp and save it.

CS8661 INTERNET PROGRAMMING LABORATORY


53 DEPT OF CSE /
Index.jsp source code
<%--
   Document   : index
   Created on : Jun 19, 2012, 8:46:45 AM
   Author     : surendran
--%>

<%@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>JSP Page</title>
   </head>
   <body>
       <h1>Hello World!</h1>
       <form name="" action="action.jsp" method="post">
Enter No1:<input  name="fst" type="text" /><br/>
Enter No2:<input  name="sec" type="text" /><br/>
<input  name="ok" type="submit" value="check" />
</form>
   </body>
</html>

5.Then create an action.jsp as follows.


Right click web page in addclient and choose new->jsp
Name:action
Click finish

CS8661 INTERNET PROGRAMMING LABORATORY


54 DEPT OF CSE /
6.click on the action.jsp  page..then right click in it and choose web service client reference ->call web service

7.The invoke the add service.

CS8661 INTERNET PROGRAMMING LABORATORY


55 DEPT OF CSE /
8. add the following code in the action.jsp
<%--
   Document   : action
   Created on : Jun 19, 2012, 8:50:03 AM
   Author     : surendran
--%>

<%@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>JSP Page</title>
   </head>
   <body>
       <h1>Hello World!</h1>
   <%-- start web service invocation --%><hr/>
            <%
String n1=request.getParameter("fst");

CS8661 INTERNET PROGRAMMING LABORATORY


56 DEPT OF CSE /
int aa=Integer.parseInt(n1);

%>
   <%
   try {
perpack.PerfectService service = new perpack.PerfectService();
perpack.Perfect port = service.getPerfectPort();
// TODO initialize WS operation arguments here
int n = aa;
// TODO process result here
java.lang.String result = port.perfectfind(n);
out.println("Result = "+result);
   } catch (Exception ex) {
// TODO handle custom exceptions here
   }
   %>
   <%-- end web service invocation --%><hr/>
   </body>
</html>

8. Finally undeploy and deploy the addclient and run it.

CS8661 INTERNET PROGRAMMING LABORATORY


57 DEPT OF CSE /
RESULT:

11. INLINE STYLE SHEETS


AIM:

To create a webpage with the following using html to embedded the style sheet

INLINE.html
<html>
<head>
<title> inline styles </title>
</head>
<body>
<p>this text doesn't have any style applied to it </p>
<p style="font-size :40pt">the style is applied to <t>"JEPPIAAR"</t>text</p>
<p style="font-size :15pt;color:red">
this text has been formated</p>
</body>
</html>
EXTERNAL.html
<html>
<head>
<title>linking to External style sheet</title>
<link rel="stylesheet"type="text/css"href="style.css"/>
</head>
<body>
<h1>Jeppiaar Engineering<em>College</em>:</h1>

CS8661 INTERNET PROGRAMMING LABORATORY


58 DEPT OF CSE /
<h2>Computer Science Engineering</h2>
<ul>
<li>Departments
<ul>
<li>CSE</li>
<li>IT</li>
<li>MCA</li>
</ul>
</li>
<li>ECE</li>
<li>EEE</li>
</ul>
<p><a class="nodec" href="http:\\www.jeppiaarcollege.org">Go to Jeppiaar website</a></p>
</body>
</html>
style.css:

BODY{background-color:green;font-family:sans-serif}
CAPTION{font-size:large;font-weight:bold}
H1{font-family:helvetica;color:blue}
H2{font-family:arial;color:red}
EMBEDDED.html:
<html>
<head>
<style type="text/css">
p.one
{
border-style:solid;
border-color:#00ff00
}
p.two
{
border-style:solid;
border-color:red blue
}
p.three
{
border-style:solid;
border-color:red blue green
}
p.four
{
border-style:solid;
border-color:red blue green
rgb(250,0,255)
}
</style></head></body>

CS8661 INTERNET PROGRAMMING LABORATORY


59 DEPT OF CSE /
<p class="one"><b>Note:</b>our college has 8 branches</p>
<p class="two"><b>Note:</b>our college has 8 branches</p>
<p class="three"><b>Note:</b>our college has 8 branches</p>
<p class="four"><b>Note:</b>our college has 8 branches</p>
</body></html>
<html>
<head>
<style type="text/css">
body{background-color:cyan}
h1{background-color:#00ff00}
h2{background-color:transparent}
p{background-color:rgb(250,0,250)}
</style>
<head>
<body>
<h1>JEC</h1>
<h2>Chennai</h2>
<p>this is a reputed college in TN</p>
<br>this college has sister institution
<br>name:Satyabama University
</body></html>

OUTPUT 1:
INLINE.html

OUTPUT 2:
12. Write programs in Java using Servlets: Session tracking using hidden form fields and Session tracking for a hit count

i).SESSION TRACKING USING HIDDEN FORM FIELDS


AIM:
To write a servlet code to implement session tracking using hidden form field.
PROGRAM:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Hidden extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res)

CS8661 INTERNET PROGRAMMING LABORATORY


60 DEPT OF CSE /
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HEAD><TITLE>Current Shopping Cart Items</TITLE></HEAD>");
out.println("<BODY>");
String[] items = req.getParameterValues("item");
out.println("You currently have the following items in your cart:<BR>");
if (items == null) {
out.println("<B>None</B>");
}
else {
out.println("<UL>");
for (int i = 0; i < items.length; i++) {
out.println("<LI>" + items[i]);
}
out.println("</UL>");
}
out.println("<FORM METHOD=GET>"); // submit to self
if (items != null) {
for (int i = 0; i < items.length; i++) {
out.println("<INPUT TYPE=HIDDEN NAME=item VALUE=\"" +
items[i] + "\">"); }
}
out.println("Would you like to<BR>");
out.println("<INPUT TYPE=SUBMIT VALUE=\" Add More Items \">");
out.println("<INPUT TYPE=SUBMIT VALUE=\" Check Out \">");
out.println("</FORM>");
out.println("</BODY></HTML>");
}
}

HTML CODE:
<html>

<head>
<title>Ordering Pen</title>

<body>
<form name=order action="http://localhost:8080/servlet/sayhello" method=POST>

Item<input type=textField name=item><br>


<input type=Submit name=submit value=Submit>

</form>
</body>

</html>
OUTPUT:

CS8661 INTERNET PROGRAMMING LABORATORY


61 DEPT OF CSE /
RESULT:

12 ii). SESSION TRACKING FOR A HIT COUNT

AIM:
To write a servlet code to implement session tracking for a hit count.

PROGRAM
import java.io.*;

import java.util.*;
import javax.servlet.*;

import javax.servlet.http.*;
public class SessionTracker extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res)


throws ServletException, IOException {

res.setContentType("text/html");
PrintWriter out = res.getWriter();

HttpSession session = req.getSession();

CS8661 INTERNET PROGRAMMING LABORATORY


62 DEPT OF CSE /
Integer count = (Integer)session.getAttribute("tracker.count");
if (count == null)

count = new Integer(1);


else

count = new Integer(count.intValue() + 1);


session.setAttribute("tracker.count", count);

out.println("<HTML><HEAD><TITLE>SessionTracker</TITLE></HEAD>");
out.println("<BODY><H1>Session Tracking Demo</H1>");

out.println("You've visited this page " + count +


((count.intValue() == 1) ? " time." : " times."));

out.println("<P>");
out.println("<H2>Here is your session data:</H2>");

Enumeration enum = session.getAttributeNames();


while (enum.hasMoreElements()) {

String name = (String) enum.nextElement();


out.println(name + ": " + session.getAttribute(name) + "<BR>");

}
out.println("</BODY></HTML>");

}
}

HTML CODE:// HAI.HTML


<html>

<head><title>sessiontracker</title></head>
<body><h3>session tracking demo</h3>

<<form name=order action="http://localhost:8080/servlet/sayhello" method=GET>

</form>
</body></html>

OUTPUT:

OUTPUT 2:
RESULT:

CS8661 INTERNET PROGRAMMING LABORATORY


63 DEPT OF CSE /
1.PHP stores the form data into a database.
AIM

To write a program to implement Ajax live search application

PROGRAM:

Nosugesstion.html

<!DOCTYPE html>
<html>

<head>
<script>

function showHint(str)
{

if (str.length==0) {
document.getElementById("txtHint").innerHTML="";

return;
} else {

var xmlhttp=new XMLHttpRequest();


xmlhttp.onreadystatechange=function() {

if (xmlhttp.readyState==4 && xmlhttp.status==200) {


document.getElementById("txtHint").innerHTML=xmlhttp.responseText;

}
}

xmlhttp.open("GET","gethint.php?q="+str,true);
xmlhttp.send();

}
}

</script>
</head>

<body>
<p><b>Start typing a name in the input field below:</b></p>

<form action="">
First name: <input type="text" id="txt1" onkeyup="showHint(this.value)">

</form>
<p>Suggestions: <span id="txtHint"></span></p>

</body>
</html>

CS8661 INTERNET PROGRAMMING LABORATORY


64 DEPT OF CSE /
GETHINT.PHP
<?PHP

$A[] = "APPLE";

$A[] = "BABY";

$A[] = "COOL";

$A[] = "KITTY";

$Q = $_REQUEST["Q"];

$HINT = "";

// LOOKUP ALL HINTS FROM ARRAY IF $Q IS DIFFERENT FROM ""

IF ($Q !== "") {

$Q = STRTOLOWER($Q);

$LEN=STRLEN($Q);

FOREACH($A AS $NAME) {

IF (STRISTR($Q, SUBSTR($NAME, 0, $LEN))) {

IF ($HINT === "") {

$HINT = $NAME;

} ELSE {

$HINT .= ", $NAME";

// Output "no suggestion" if no hint was found or output correct values

echo $hint === "" ? "no suggestion" : $hint;

?>

CS8661 INTERNET PROGRAMMING LABORATORY


65 DEPT OF CSE /

You might also like