0% found this document useful (0 votes)
31 views91 pages

Cs8661 Ip Rec

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 91

EX.

NO:1 CREATE A WEB PAGE WITH THE FOLLOWING USING HTML


A. TO EMBED A MAP IN A WEB PAGE

DATE: B. TO FIX THE HOT SPOTS IN THAT MAP


C. SHOW ALL THE RELATED INFORMATION WHEN THE HOT
SPOTS ARE CLICKED.

AIM:
To create a web page which includes a map and display the related information when a
hotspot is clicked in a map.

ALGORITHM:
1. Start the program for embed map in web page
2. Create world.html file using notepad
3. The <map> tag is used to define a client-side image-map.
4. An image-map is an image with clickable areas.
5. The name attribute is required in the map element. This attribute is associated with the
<img> usemap attribute and creates a relationship between the image and the map.
6. The map element contains a number of area elements that defines the clickable areas in the
image map.
7. Set the coordination for the Hotspot areas
8. Finally terminate the program and embed web page.

CS8661-INTERNET PROGRAMMING LABORATORY 1


PROGRAM:
WORLD.HTML:
<html>
<head>
<title>WORLD INFORMATION</title>
</head>
<body>
<p>Click on the map </p>
<img height=300 width=800 src="C:\Documents and Settings\Owner\Desktop\wt lab manual
2010\pgm1\worldmap.jpg" width="700" height="300" alt="world" usemap="#world" />
<map name="world">
<area name="africa" shape="circle" coords="420,180,55" href="africa.html" />
<area name="australia" shape="rect" coords="790,280,20,80" href="australia.html" /> </map>
<br><p><h1 style="background-color:red" style="font-family:verdana"> GENERAL
INFORMATION ABOUT OUR WORLD</h1></p>
</br>
<small><i>
<ul><h2>
<li>Most Populated Country:China Population 1,307,000,000</li>
<li>World’s Tallest Mountain: Mt. Everset in Nepal 29,025ft.(8.850m)</li>
<li> World’s Lowest Point: The lowest point on dry land is the shore of the Dead Sea, shared by
Israel and Jordan, 418 m (1,371 ft) below sea level.</li>
<li> World’s Deepest Point: Russia's Lake Baikal, located north of the Mongolian border, is the
world's deepest with a maximum depth of just over one mile (5371 feet / 1637 meters).</li>
<li> World’s Longest River: Africa's Nile River is the world's longest at 4,160 miles (6,695
kilometers) long.</li>
<li> World’s Largest Desert: Outside of polar regions, Northern Africa's Sahara Desert is the
world's largest desert at more than 3.5 million square miles (9 million square kilometers), which
is slightly smaller that the size of the United States</li>
<li> World’s Largest City: Tokyo-Yokohama, Japan - 33,200,000</li></p>
</h2></ul>

CS8661-INTERNET PROGRAMMING LABORATORY 2


</i></small>
</body>
</html>

AFRICA.HTML:
<head>
<title>AFRICA</title>
<h1 align=center>Africa includes 53 Individual Countries</h1>
<br>
<p>
<img align="left" src="C:\Documents and Settings\Owner\Desktop\wt lab manual 2010\pgm
1\imagesCA1BWOB7.jpg" height=320 width=320></img></p>
</br>
<table border=5>
<tr>
<th align=left>Continent Size:</th>
<td align=left>11,700,000 square miles</td>
</tr>
<tr>
<th align=left>Estimated Population:</th>
<td align=left>877 million people</td>
</tr>
<tr>
<th align=left>Largest Country:</th>
<td align=left>Sudan, 968,000 square miles</td>
</tr>
<tr>
<th align=left>Longest River:</th>
<td align=left>Nile, 4,160 miles </td>
</tr>
</table>

CS8661-INTERNET PROGRAMMING LABORATORY 3


</body>

AUSTRALIA.HTML:
<head>
<title>Australia</title>
<h1 align=center>Austalia is the 6th largest country and the smallest continent.</h1>
<br>
<p>
<img align="left" src="C:\Documents and Settings\Owner\Desktop\wt lab manual 2010\pgm
1\australia.jpg" height=320 width=320></img></p>
</br>
<table border=5>
<tr>
<th align=left>Continent Size:</th>
<td align=left>7,682,300 square km</td>
</tr>
<tr>
<th align=left>Estimated Population:</th>
<td align=left>21 million people</td>
</tr>
<tr>
<th align=left>land masses:</th>
<td align=left>mainland and Tasmania</td>
</tr>
<tr>
<th align=left>Largest Desert:</th>
<td align=left>The Great Victoria Desert</td>
</tr>
</table>
</body>

CS8661-INTERNET PROGRAMMING LABORATORY 4


OUTPUT:

CS8661-INTERNET PROGRAMMING LABORATORY 5


RESULT:

Thus the program for image mapping is successfully executed and output is verified.

CS8661-INTERNET PROGRAMMING LABORATORY 6


EX.NO:2 CREATE A WEB PAGE WITH THE FOLLOWING.
A. CASCADING STYLE SHEETS.

DATE: B. EMBEDDED STYLE SHEETS.


C. INLINE STYLE SHEETS. USE OUR COLLEGE INFORMATION
FOR THE WEB PAGES.

AIM:
To create a web page with the following Cascading style sheets (CSS)
 Inline style
 Embedded style
 External style
ALGORITHM:
1. Start by three ways of employing CSS in your Web pages :inline styles, embedded or
global styles, and linked or external style sheets.
2. To create an inline style
a. Add the style attribute to the HTML tag.
b. The style declaration must be enclosed within double quotation marks.
3. To create an embedded style
a. Insert a <style> tag within the head section of HTML file.
b. Within the <style> tag, enclose the style declarations need to the entire Web page.
c. The style sheet language identifies the type of style used in the document.
d. The default and the most common language is “text/css” for use with CSS.
4. To create an External styles
a. Create a text file containing style declarations
b. Create a link to that file in each page of the Web site using a <link> tag.
c. Specify the link attributes, such as href, rel, and type.
d. Link a style sheet, the value of the href attribute should be the “URL” of the linked
document, the value of the rel attribute should be “stylesheet” and the value of the type
attribute should be “text/css”.
5. Write the source code for the separate style sheet and finally terminate the program.

CS8661-INTERNET PROGRAMMING LABORATORY 7


PROGRAM:

HOME.HTML:

<html>
<head>
<title>CASCADING STYLE SHEET</title>
</head>
<body alink="blue" vlink="brown">
<h1><u><b><font face="Monotype corsiva" color="red">
Different types of Cascading Style Sheets</font></b></u></h1>
</ a href="inline.html" style="text-decoration:none:">1.INLINE STYLE SHEET</a></br>
<a href="embed.html" style="text-decoration:none:">1.EMBEDED STYLE SHEET</a></br>
<a href="external.html" style="text-decoration:none:">1.EXTERNAL STYLE
SHEET</a></br><fontface="arial" size="6">
</body>
</html>

INLINE.HTML:

<html>
<head>
<title>INLINE STYLE SHEET</title>
</head>
<body>
<ol class="decimal">
<h1 style="font-family":Times New Roman,sans-serif;font-size;20pt;
color:green"><li>Inline Style Sheet</li></h1>
<h3>

CS8661-INTERNET PROGRAMMING LABORATORY 8


<p style="text-indent:30pt;color:blue;font-family:serif;font-size:16pt"> an Inline style is a css or
cascading style sheets-style which is written directly on the element it affects.It is also known as
inline css.</p>
</h3
</ol>
</body>
</html>

EMBED.HTML:

<html>
<head>
<title>EMBEDDED STYLE SHEET</title>
<style type="text/css">
ol.a{list-style-type:lower-roman}
h1{
font-family:arial black;
font-size:30pt;
color:orange;
text-align:center;}
h3{
font-family:arial black;
font-size:16pt;
color:blue;
text=align:left;}
</style>
</head>
<body>
<ol class="a">
<h1>
<li>Embedded style sheet</li></h1>

CS8661-INTERNET PROGRAMMING LABORATORY 9


</br>
<h3>
Embedded style sheets refer to when you embed style sheet information into an html document
using the style element.</h3></ol>
</body>
</html>

EXTERNAL.HTML:

<html>
<head>
<title>IMPORTED STYLE SHEET</title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<h1>External Style Sheet</h1>
<h3>An External style sheet is ideal when the style is applied to many pages.with an external
style sheet,Each page must link to the style sheet using the<link>tag.</h3>
</body>
</html>

STYLE1.CSS:

body{background-color:#EEEEFF;colr:black;}
h1{font-family:arial black;font-size:25pt;color:orange;text-align:center;}
h3{text-indent:30pt;font -family:arial black;font-size:12pt; color:blue;text-align:left;}

CS8661-INTERNET PROGRAMMING LABORATORY 10


OUTPUT:

CS8661-INTERNET PROGRAMMING LABORATORY 11


RESULT:
Thus the Web page with all types of Cascading style sheets is successfully executed.

CS8661-INTERNET PROGRAMMING LABORATORY 12


EX.NO:3 VALIDATE THE REGISTRATION, USER LOGIN, USER PROFILE AND
PAYMENT BY CREDIT CARD PAGES USING JAVASCRIPT.

DATE:

AIM:

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

ALGORITHM:
1. Start the program
2. Create Registration.html file using notepad
3.Insert the data into the user login account.
4. An User profile can be updated by java script.
5. The name attribute is required in the payment element. This attribute is associated with the
Credir card attribute and creates a relationship between the user profile and payment.

PROGRAM:

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>

CS8661-INTERNET PROGRAMMING LABORATORY 13


<body bgcolor=”pink”>

<br><br>

<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>

CS8661-INTERNET PROGRAMMING LABORATORY 14


<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;

if(flag==1)

CS8661-INTERNET PROGRAMMING LABORATORY 15


{

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:

CS8661-INTERNET PROGRAMMING LABORATORY 16


<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;

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

x=str.substr(i,1)

if(!(x<=9))

flag=0;

break;

CS8661-INTERNET PROGRAMMING LABORATORY 17


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:

CS8661-INTERNET PROGRAMMING LABORATORY 18


<html>

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

<script language="javascript">

function validate()

var flag=1;

if(document.myform.title.value=="")

flag=0;

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;

CS8661-INTERNET PROGRAMMING LABORATORY 19


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>

CS8661-INTERNET PROGRAMMING LABORATORY 20


Shopping cart:

Catalog.html:

<html>

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

<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;

CS8661-INTERNET PROGRAMMING LABORATORY 21


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

BOOKS

CS8661-INTERNET PROGRAMMING LABORATORY 22


:<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=="")

CS8661-INTERNET PROGRAMMING LABORATORY 23


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.lenght;i++)

x=str.substr(i,1);

if(!(x<=9))

flag=0;

break;

if(flag==1)

CS8661-INTERNET PROGRAMMING LABORATORY 24


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 Conformation

CS8661-INTERNET PROGRAMMING LABORATORY 25


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>

</body>

</html>

OUTPUT:

RESULT:

Thus the resitration form with all types of checking process is successfully executed.

CS8661-INTERNET PROGRAMMING LABORATORY 26


EX NO:4.A

DATE: INVOKE SERVLET FROM HTML

AIM:

To write a html program for invoking servlet using html.

ALGORITHM:

1. In html program, define the html, head and title tag.


2. Give the title as Invoking Sevlets from HTML and close title and head tag.
3. Define the body tag to create form and table simultaneously.
4. The table consists information like employee name, phone number, salary and id
5. In the servlet program, import the summary package and create a own servlet class
extends with generic servlet.
6. Define the service method to implement request and response.
7. Create the object for print writer and get writer() value.
8. Get the servlet request parameter.
9. Create objects for string method and it should display another object value received using
get.
10. Display the result and stop the execution of program.

PROGRAM :

<HTML>
<head>
<TITLE>INVOKING SERVLET FROM HTML</TITLE>
</head>
<BODY>
<CENTER>

CS8661-INTERNET PROGRAMMING LABORATORY 27


<FORM name = "PostParam" method = "Post" action="http://localhost:8080/servlets-
examples/servlet/serv">
<TABLE>
<tr>
<td><B>Employee: </B></td>
<td><input type = "textbox" name="ename" size="25"
value=""></td>
</tr>
<tr>
<td><B>Phone: </B></td>
<td><input type = "textbox" name="phoneno" size="25"
value=""></td>
</tr>
<tr>
<td><b>Salary: </b></td>
<td><input type="textbox" name="salary" size="25" value=""></td>
</tr>
<tr>
<td><b>Id:</b></td>
<td><input type="textbox" name="id" size="25" value=""></td>
</tr>
</TABLE>
<INPUT type = "submit" value="Submit">
</FORM>
</CENTER>
</body>
</html>

SERVLET CODE:

import java.io.*;
import java.util.*;

CS8661-INTERNET PROGRAMMING LABORATORY 28


import javax.servlet.*;
public class serv extends GenericServlet
{
public void service(ServletRequest request,ServletResponse response)throws
ServletException,IOException
{
PrintWriter out=response.getWriter();
String name=request.getParameter("ename");
String phno=request.getParameter("phoneno");
String sal=request.getParameter("salary");
String id=request.getParameter("id");
out.println("EmployeeName: "+name);
out.println("Phone No: "+phno);
out.println("id: "+id);
out.println("Salary: "+salary);

}
}

OUTPUT:

CS8661-INTERNET PROGRAMMING LABORATORY 29


RESULT:
Thus the program for invoking servlet from HTML has been implemented successfully
and the output has verified.

CS8661-INTERNET PROGRAMMING LABORATORY 30


EX NO:4. B

DATE: SESSION TRACKING USING HIDDEN FORM FIELDS

AIM:

To write a program to implement session tracking using hidden form fields.

ALGORITHM:

Step 1: Start the program.

Step 2: Import the necessary packages.

Step 3: Create a class Show Session which inherits HttpServlet.

Step 4: Use doGet() method to get request parameter and also implement necessary exception
handling mechanism.

Step 5: Get the session and calculate access count.

Step 6: Set the necessary attributes and get access time.

Step 7: Display the result and stop the execution of program.

SESSION TRACKING USING HIDDEN FORM FIELDS

newhtml.html

<html>

<head>

<title></title>

CS8661-INTERNET PROGRAMMING LABORATORY 31


<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>

<body>

<form action="servlet1">

Name:<input type="text" name="userName"/><br/>

<input type="submit" value="go"/>

</form>

</body>

</html>

FirstServlet.java

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class FirstServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response){

try{

response.setContentType("text/html");

PrintWriter out = response.getWriter();

String n=request.getParameter("userName");

out.print("Welcome "+n);

//creating form that have invisible textfield

CS8661-INTERNET PROGRAMMING LABORATORY 32


out.print("<form action='SecondServlet'>");

out.print("<input type='hidden' name='uname' value='"+n+"'>");

out.print("<input type='submit' value='go'>");

out.print("</form>");

out.close();

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

SecondServlet.java

import java.io.*;

import javax.servlet.ServletException;

import javax.servlet.http.*;

public class SecondServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response) throws


ServletException, IOException {

try{

response.setContentType("text/html");

PrintWriter out = response.getWriter();

//Getting the value from the hidden field

String n=request.getParameter("uname");

out.print("Hello "+n);

CS8661-INTERNET PROGRAMMING LABORATORY 33


out.close();

catch(Exception e)

System.out.println(e);}

OUTPUT:

CS8661-INTERNET PROGRAMMING LABORATORY 34


CS8661-INTERNET PROGRAMMING LABORATORY 35
RESULT:
Thus the program for session tracking using hidden form fields has been implemented
successfully and the output has verified.

CS8661-INTERNET PROGRAMMING LABORATORY 36


EX NO:5

DATE: PROGRAM TO CREATE 3 TIER APPLICATION USING SERVLET


FOR CONDUCTING ONLINE EXAMINATION FOR DISPLAYING
STUDENT MARK LIST

AIM:
To write servlet program to conduct online examination and to update mark in a database.

ALGORITHM:

Step 1: Create the database


Step 2: Establish ODBC Connectivity
Step 3: Write the servlet program having coding for both client side and server side.
Step 4: Include validation script and jdbc connectivity coding.
Step 5: Execute the program.
Step 6: Check the update in database.
Step 7: Stop

PROGRAM:
SERVLET CODE:
<%@ page language="java" import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%
String SeatNum,Name;
String ans1,ans2,ans3,ans4,ans5;
int a1,a2,a3,a4,a5;
a1=a2=a3=a4=a5=0;
Connection connect=null;

CS8661-INTERNET PROGRAMMING LABORATORY 37


Statement stmt=null;
ResultSet rs=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:DB";
connect = DriverManager.getConnection(url, "", "");
if(request.getParameter("action")!=null)
{
SeatNum = request.getParameter("Seat_no");
Name = request.getParameter("Name");
ans1 =request.getParameter("group1");
if(ans1.equals("True"))
a1=2;
else
a1=0;
ans2 = request.getParameter("group2");
if(ans2.equals("True"))
a2=0;
else
a2=2;
ans3 = request.getParameter("group3");
if(ans3.equals("True"))
a3=0;
else
a3=2;
ans4 = request.getParameter("group4");
if(ans4.equals("True"))
a4=2;
else
a4=0;
ans5 = request.getParameter("group5");
if(ans5.equals("True"))

CS8661-INTERNET PROGRAMMING LABORATORY 38


a5=0;
else
a5=2;
int Total=a1+a2+a3+a4+a5;
stmt = connect.createStatement();
String query = "INSERT INTO StudentTable (" + "Seat_no,Name,Marks" + ") VALUES ('"
+SeatNum + "', '" + Name + "', '"+Total+ "')";
int result = stmt.executeUpdate(query);
stmt.close();
stmt = connect.createStatement();
query = "SELECT * FROM StudentTable WHERE Name="+"'"+Name+"'";
rs = stmt.executeQuery(query);
%>
<html><head><title>Student Mark List</title></head>
<body bgcolor=lightgreen>
<center>
<h2>Students Marksheet</h2>
<h3>Name of the College:ABC College of Engineering</h3>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td><b>Seat_No</b></td>
<td><b>Name</b></td>
<td><b>Marks</b></td>
</tr>
<%
while(rs.next())
{
%>
<tr>
<td><%=rs.getInt(1)%></td>
<td><%=rs.getString(2)%></td>

CS8661-INTERNET PROGRAMMING LABORATORY 39


<td><%=rs.getString(3)%></td>
</tr>
<%
}
rs.close();
stmt.close();
connect.close();
%>
</table>
</center>
<br/><br/><br/>
<table>
<tr><td><b>Date:<%=new java.util.Date().toString() %></td></tr>
<tr><td><b>Signature: X.Y.Z. <b></td></tr>
</table>
<div>
<a href="http://127.0.0.1:8080/jsp-examples/StudExam/index.jsp">Click here to go back</a>
</body>
</html>
<%}else{%>
<html>
<head><title>Online Examination</title>
<script language="javascript">
function validation(Form_obj)
{
if(Form_obj.Seat_no.value.length==0)
{
alert("Please,fill up the Seat Number");
Form_obj.Seat_no.focus();
return false;
}

CS8661-INTERNET PROGRAMMING LABORATORY 40


if(Form_obj.Name.value.length==0)
{
alert("Please,fill up the Name");
Form_obj.Name.focus();
return false;
}
return true;
}
</script>
</head>
<body bgcolor=lightblue>
<center>
<h1>OnLine Examination</h1>
</center>
<form action="index.jsp" method="post"
name="entry" onSubmit="return validation(this)">
<input type="hidden" value="list" name="action">
<table>
<tr>
<td><h3>Seat Number:</h3></td>
<td><input type="text" name="Seat_no"></td>
</tr>
<tr>
<td><h3>Name:</h3></td>
<td><input type="text" name="Name" size="50"></td>
</tr>
<hr/>
<tr>
<td><b>Total Marks:10(Each question carries equal marks) </b></td>
<td></td><td></td><td></td><td><b>Time: 15 Min.</b></td>
</tr>

CS8661-INTERNET PROGRAMMING LABORATORY 41


</table>
<hr/>
<b>1. Apache is an open source web server</b><br/>
<input type="radio" name="group1" value="True">True
<input type="radio" name="group1" value="False">False<br>
<br/>
<b>2. In Modern PC there is no cache memory.</b><br/>
<input type="radio" name="group2" value="True">True
<input type="radio" name="group2" value="False">False<br>
<br/>
<b>3. Tim-Berner Lee is the originator of Java.</b><br/>
<input type="radio" name="group3" value="True">True
<input type="radio" name="group3" value="False">False<br>
<br/>
<b>4.JPG is not a video file extension.</b><br/>
<input type="radio" name="group4" value="True">True
<input type="radio" name="group4" value="False">False<br>

<br/>
<b>5. HTTP is a statefull protocol</b><br/>
<input type="radio" name="group5" value="True">True
<input type="radio" name="group5" value="False">False<br>
<hr/>

<center>
<input type = "submit" value="Submit">
<input type = "reset" value="Clear"><br><br>
</center>
</form>
<%}%>

CS8661-INTERNET PROGRAMMING LABORATORY 42


OUTPUT:

CS8661-INTERNET PROGRAMMING LABORATORY 43


RESULT:

Thus the java servlet programs to conduct online examination and to display student mark list
available in a database was successfully executed and verified.

CS8661-INTERNET PROGRAMMING LABORATORY 44


EX NO:6
INSTALLING & CONFIGURING TOMCAT WEBSERVER
DATE:

AIM :
To Install & Configure TOMCAT web server.
PROCEDURE:
1. Visit Apache Tomcat home page with a Web browser, and click the "Download" link under
the "Tomcat 7.0.70 Released" section. You will see the "Tomcat 7 Downloads" page.
2. Click "32-bit Windows zip" link under "Binary Distributions" section. You will see the
download file save dialog box.(this supports jdk1.6 kit)
3. Use the "Save file" option to save the download file "apache-tomcat-7.0.70-windows-x86.zip"
to a temporary folder.
4. Unzip "apache-tomcat-7.0.70-windows-x86.zip" to file installation folder “C:\ apache-tomcat-
7.0.70”
5. Try to start Tomcat server by running the "startup" command in a command line window:
C:\ >cd apache-tomcat-7.0.70\bin
C:\ >cd apache-tomcat-7.0.70\bin>startup
The CATALINA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
6. To fix the missing environment variables, CATALINA_HOME,JAVA_HOME &
JRE_HOME,
 Click my computer->right click properties->Select Advance System Setting
 In this tab, Click Environment variable
 Click new in User variables for admin
 Enter variable name & Variable value
 CATALINA_HOME C:\apache-tomcat-7.0.70
 JAVA_HOME C:\Program Files\Java\
 JRE_HOME C:\Program Files\Java\jre7

CS8661-INTERNET PROGRAMMING LABORATORY 45


7. Configuring Tomcat
Open “C:\apache-tomcat-7.0.70\conf” folder
It consiste of the following xml files
Server.xml
Web.xml
Tomcat-user.xml
Context.xml
Open web.xml in notepad & modify default-listings-false to true
Open server.xml & change port number 8080 to anyother(8081)if any application access
the same port
Open context.xml change reloadable attribute to true
Configuration procedure varies according to the version
8. Try to start Tomcat server by running the "startup" command in a command line window:

CS8661-INTERNET PROGRAMMING LABORATORY 46


RESULT:
Thus, tomcat server is started.

CS8661-INTERNET PROGRAMMING LABORATORY 47


CREATING SERVLET USING TOMCAT SERVER

AIM :
To create a servlet program & run it on tomcat server

PROCEDURE:
Steps to create the servlet using Tomcat server
1. Create a directory structure
C:\apache-tomcat-7.0.70\\webapps
Create folder HELLO
Create folder WEB-INF
Create folder classes
2. Create a Servlet program using notepad(hw.java)
3. Save hw.java in D:\java\jdk1.6.0\bin
4. Compile servlet using following command
D:\Java\jdk1.6.0\bin>javac -classpath C:\apache-tomcat-7.0.70\lib\servlet-api.jar
hw.java
D:\Java\jdk1.6.0\bin>
5. Copy the hw.class file
6. Paste it into “C:\apache-tomcat-7.0.70\\webapps\HELLO\WEB-INF\classes”
folder
7. Copy web.xml file from “C:\apache-tomcat-7.0.70\webapps\ROOT\WEB-INF”
and paste it into “C:\apache-tomcat-7.0.70\\webapps\HELLO\WEB-INF”
8. Open web.xml in your project HELLO and type the deployment descriptor coding
9. Start the Tomcat server (startup)
10. Open the browser and access the file http://localhost:8080/HELLO/hw

CS8661-INTERNET PROGRAMMING LABORATORY 48


PROGRAM:
hw.java

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

// Extend HttpServlet class


public class hw extends HttpServlet {

public void doGet(HttpServletRequest request,HttpServletResponse response)throws


ServletException, IOException
{
// Set response content type
response.setContentType("text/html");

// Actual logic goes here.


PrintWriter out = response.getWriter();
out.println("<h1>HAI</h1>");
out.close();
}
}
web.xml
<display-name>Welcome to Tomcat</display-name>
<description>Welcome to Tomcat</description>
<servlet>
<servlet-name>hw</servlet-name>
<servlet-class>hw</servlet-class>
</servlet>
<servlet-mapping>

CS8661-INTERNET PROGRAMMING LABORATORY 49


<servlet-name>hw</servlet-name>
<url-pattern>/hw</url-pattern>
</servlet-mapping>
</web-app>

OUTPUT:

RESULT:
Thus, the servlet program has been executed in tomcat webserver

CS8661-INTERNET PROGRAMMING LABORATORY 50


ONLINE SHOPPING CART USING JSP & COOKIES

AIM:
To create a online shopping cart & maintain session information using cookies using jsp.

PROCEDURE:
1. Create a webpage to show the products information and design a form to collect the
details
2. Invoke jsp program to display the cart details of the user
3. Use cookies to identify whether the user is a new user or existing user
4. If the user has already visited the site ,then display his old order details also.

SAMPLE PROGRAM:
cart.html
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<frameset rows="15%,75%">
<frame name="f1" src="head.html">
<frameset cols="15%,75%">
<frame name="f2" src="links.html">
<frame name="f3" >
</frameset>
</frameset>
</body>
</html>

CS8661-INTERNET PROGRAMMING LABORATORY 51


head.html
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="gold">
<center> <h1>COMPANY PRODUCTS</h1> </center>
</body>
</html>
links.html
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="silver">
<a href="log.html" target="f3">PRODUCTS</a>

</body>
</html>
log.html
<html>
<body>
<center>WELCOME TO OUR SITE</center><br>
<form name="form1" action="http://localhost:9816/WebApplication1/order"
mathod="GET">
Name<input type="text" name="t1"><br><br>
Select Item in the List<br><br>
<select name="products" >
<option value="0">None</option>

CS8661-INTERNET PROGRAMMING LABORATORY 52


<option value="1">MobilePhone</option>
<option value="2">Camera</option>
<option value="3">Laptop</option>
<option value="4">Bag</option>
</select>
<br><br>
<input type="submit" value="SUBMIT">
<input type="reset" value="CLEAR">
</form>
</body>
</html>

order.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.Cookie;
public class order extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)throws
ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String uname=request.getParameter("t1");
String item=request.getParameter("products");
String op=new String();

CS8661-INTERNET PROGRAMMING LABORATORY 53


switch(Integer.parseInt(item))
{
case 1:
op="Mobile Phones";
break;
case 2:
op="Camera";
break;
case 3:
op="Laptop";
break;
case 4:
op="Bag";
break;
}
out.println("<html><body>");
Cookie[] ck=request.getCookies();
if(ck==null)
{
Cookie c1=new Cookie("NAME",uname);
Cookie c2=new Cookie("ITEM",op);
response.addCookie(c1);
response.addCookie(c2);
out.println("Welcome Thanks for shopping<br>");
}
else
{
Cookie c3=new Cookie("ITEM",op);
response.addCookie(c3);
out.println("Hi! "+ck[0].getValue()+" Your Last Order is:");
for(int i=1;i<ck.length;i++)

CS8661-INTERNET PROGRAMMING LABORATORY 54


out.println(“<br>” +ck[i].getValue()+"<br>");
}
out.println("<h1>Your New Order is: " + op + "</h1>");
out.println("</body>");
out.println("</html>");
out.close();
} } }
OUTPUT:

CS8661-INTERNET PROGRAMMING LABORATORY 55


CS8661-INTERNET PROGRAMMING LABORATORY 56
RESULT:
Thus online shopping cart application has been created successfully.

CS8661-INTERNET PROGRAMMING LABORATORY 57


EX NO:7 REDO THE PREVIOUS TASK USING JSP BY CONVERTING THE
STATIC WEB PAGES INTO DYNAMIC WEB PAGES. CREATE A
DATE: DATABASE WITH USER INFORMATION AND BOOKS
INFORMATION. THE BOOKS CATALOGUE SHOULD BE
DYNAMICALLY LOADED FROM THE DATABASE.

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>

CS8661-INTERNET PROGRAMMING LABORATORY 58


<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.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>

CS8661-INTERNET PROGRAMMING LABORATORY 59


</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 60


<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>

CS8661-INTERNET PROGRAMMING LABORATORY 61


</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:

Order.html:

<html>

<body><br /><br />

CS8661-INTERNET PROGRAMMING LABORATORY 62


<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.*"%>

CS8661-INTERNET PROGRAMMING LABORATORY 63


<%@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)

out.println("<br><br>SORRY INVALID ID TRY AGAIN

ID<br><br>");

out.println("<a href=\"login.html\">press LOGIN to

RETRY</a>");

CS8661-INTERNET PROGRAMMING LABORATORY 64


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");

CS8661-INTERNET PROGRAMMING LABORATORY 65


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;

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

CS8661-INTERNET PROGRAMMING LABORATORY 66


{ 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>");

CS8661-INTERNET PROGRAMMING LABORATORY 67


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

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>");

CS8661-INTERNET PROGRAMMING LABORATORY 68


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>");

CS8661-INTERNET PROGRAMMING LABORATORY 69


}

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");

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;

CS8661-INTERNET PROGRAMMING LABORATORY 70


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>");

CS8661-INTERNET PROGRAMMING LABORATORY 71


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

RETRY</a>");

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

con.close();

%>

OUTPUT:

CS8661-INTERNET PROGRAMMING LABORATORY 72


RESULT:
Thus The books catalogue should be dynamically loaded from the database has been executed
and the output is verified successfully.

CS8661-INTERNET PROGRAMMING LABORATORY 73


EX NO:8 CREATE AND SAVE AN XML DOCUMENT AT THE SERVER, WHICH
CONTAINS 10 USERS INFORMATION. WRITE PROGRAM, WHICH
DATE: TAKES USER ID AS INPUT AND RETURNS THE USER DETAILS BY
TAKING THE USER INFORMATION FROM XML DOCUMENT.

AIM:

To write a program that accepts user id as input and displays the user details by retrieving the
user information from the XML document.

ALGORITHM:

1. Start the program to create and process XML document.


2. Create an XML document with necessary attributes and values for user information.
3. Save XML document in a server which contains information of user.
4. Use ActiveXObject to invoke the load method by specifying XML file.
5. Prompt a user to enter used_id.
6. Retrieve information from XML file using for loop.
7. Display the result and stop the execution of program.

PROGRAM:

USER INFORMATION

<?xml version="1.0"?>

<userdata>

<user1>

<jntuno>561</jntuno>

<name> chandu</name>

<phno>9989891510</phno>

<address>srikakulam</address>

CS8661-INTERNET PROGRAMMING LABORATORY 74


</user1>

<user2>

<jntuno>540</jntuno>

<name> karteek</name>

<phno>9701443556</phno>

<address>srikakulam1</address>

</user2>

<user3>

<jntuno>525</jntuno>

<name> giri</name>

<phno>9897895301</phno>

<address>rajam</address>

</user3>

<user4>

<jntuno>526</jntuno>

<name>gopi</name>

<phno>9999789540</phno>

<address>parlakimidi</address>

</user4>

<user5>

<jntuno>513</jntuno>

CS8661-INTERNET PROGRAMMING LABORATORY 75


<name> manoj</name>

<phno>9989233331</phno>

<address>hyderabad</address>

</user5>

<user6>

<jntuno>514</jntuno>

<name> balaji</name>

<phno>9999789560</phno>

<address>vizag</address>

</user6>

<user7>

<jntuno>567</jntuno>

<name>kiran </name>

<phno>9999178957</phno>

<address>vijayanagaram</address>

</user7>

<user8>

<jntuno>518</jntuno>

<name> sekhar</name>

<phno>789580</phno>

<address>bobili</address>

CS8661-INTERNET PROGRAMMING LABORATORY 76


</user8>

<user9>

<jntuno>517</jntuno>

<name>chaitu</name>

<phno>789590</phno>

<address>sallur</address>

</user9>

<user10>

<jntuno>595</jntuno>

<name> sravan</name>

<phno>9000789500</phno>

<address>sklm</address>

</user10>

</userdata>

INFORMATION RETRIVAL

<html>

<!--DOM with javascript>

<head>

<title>user profile example</title>

</head>

<body>

CS8661-INTERNET PROGRAMMING LABORATORY 77


<script type="text/JavaScript">

var xmldoc=new ActiveXObject("Microsoft.XMLDOM");

xmldoc.load("data.xml");

var ele=xmldoc.documentElement;

var y=window.prompt("eneter user num",1);

var node=ele.childNodes.item(y-1);

for(var i=0;i<node.childNodes.length;i++)

var child=node.childNodes.item(i);

var val=child.firstChild;

document.write("<h2>"+child.nodeName+":"+val.nodeValue);

</script>

</body>

</html>

CS8661-INTERNET PROGRAMMING LABORATORY 78


OUTPUT:

RESULT:

Thus the program to create XML file for retrieving user information has been successfully
executed and the output was verified.

CS8661-INTERNET PROGRAMMING LABORATORY 79


EX NO:9.A

DATE: VALIDATE THE FORM USING PHP REGULAR EXPRESSION

PROGRAM:

Form.html

<form action="http://foo.com/foo.php" method="get"> <div> City: <input name="city" /> <br />
State: <input name="state" size="2" maxlength="2" /> <br /> ZIP: <input name="zip" size="5"
maxlength="5" /> <br /> <input type="submit" /> </div></form>

Basic server-side validation code

$state = $_REQUEST["state"];
if (!preg_match("/[A-Z]{2}/", $state)) {
?>
<h2>Error, invalid state submitted.
</h2>
<?php
}

OUTPUT:

RESULT:

Thus the program to validate the form using php has been successfully executed and the output
was verified.

CS8661-INTERNET PROGRAMMING LABORATORY 80


EX NO:9.B

DATE: PHP STORES A FORM DATA INTO DATABASE

AIM:

Write the php program to stores a form data into database.

ALGORITHM:

1. Import necessary php packages


2. Create the form to enter data.
3. Stores the all data in the database .
4. Read the input string in database.
5. Test whether the given data in database is correct or incorrect.

PROGRAM:

<html>

<head>
<style>
.error {color: #FF0000;}
</style>
</head>

<body>
<?php
// define variables and set to empty values
$nameErr = $emailErr = $genderErr = $websiteErr = "";
$name = $email = $gender = $comment = $website = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
}else {
$name = test_input($_POST["name"]);

CS8661-INTERNET PROGRAMMING LABORATORY 81


}

if (empty($_POST["email"])) {
$emailErr = "Email is required";
}else {
$email = test_input($_POST["email"]);

// check if e-mail address is well-formed


if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}

if (empty($_POST["website"])) {
$website = "";
}else {
$website = test_input($_POST["website"]);
}

if (empty($_POST["comment"])) {
$comment = "";
}else {
$comment = test_input($_POST["comment"]);
}

if (empty($_POST["gender"])) {
$genderErr = "Gender is required";
}else {
$gender = test_input($_POST["gender"]);
}
}

function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>

<h2>Absolute classes registration</h2>

<p><span class = "error">* required field.</span></p>

<form method = "post" action = "<?php


echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

CS8661-INTERNET PROGRAMMING LABORATORY 82


<table>
<tr>
<td>Name:</td>
<td><input type = "text" name = "name">
<span class = "error">* <?php echo $nameErr;?></span>
</td>
</tr>

<tr>
<td>E-mail: </td>
<td><input type = "text" name = "email">
<span class = "error">* <?php echo $emailErr;?></span>
</td>
</tr>

<tr>
<td>Time:</td>
<td> <input type = "text" name = "website">
<span class = "error"><?php echo $websiteErr;?></span>
</td>
</tr>

<tr>
<td>Classes:</td>
<td> <textarea name = "comment" rows = "5" cols = "40"></textarea></td>
</tr>

<tr>
<td>Gender:</td>
<td>
<input type = "radio" name = "gender" value = "female">Female
<input type = "radio" name = "gender" value = "male">Male
<span class = "error">* <?php echo $genderErr;?></span>
</td>
</tr>

<td>
<input type = "submit" name = "submit" value = "Submit">
</td>

</table>

</form>

<?php
echo "<h2>Your given values are as:</h2>";

CS8661-INTERNET PROGRAMMING LABORATORY 83


echo $name;
echo "<br>";

echo $email;
echo "<br>";

echo $website;
echo "<br>";

echo $comment;
echo "<br>";

echo $gender;
?>

</body>
</html>

OUTPUT:

RESULT:
Thus the form of database has been created successfully.

CS8661-INTERNET PROGRAMMING LABORATORY 84


EX NO:
CREATING A WEBSERVICE FOR COLLECTING PEOPLE’S
DATE:
OPINION

AIM:
To create a web service in java to collect people’s opinion about a product to predict its
sale.

PROCEDURE:
1.Install Netbeans IDE
STEPS TO CREATE WEBSERVICE
1. Create project
Open Netbeans >> Select File >> New Project >> Java Web -> Web Application:
Click Next >> Enter Project name: ‘WC1’:
Click Next >> Select Server->Click Finish
2. Create WebService
Right click on the project ‘wc1’ >> New >> Web Service:
Enter Web service name: two-Enter Package: com.prgguru.example
Click Finish
3. Adding an Operation to the Web Service
The NetBeans IDE provides a dialog for adding an operation to a web service. Right Click
the ‘two’ webservice. Click Add Operation. The Add Operation dialog opens Add Operation
dialog box, type FeedBack in Name and type String in the Return Type drop-down list.
4. In the lower part of the Add Operation dialog box, click Add and create a parameter of
type int named Name,City,Comment as String type.
5. Click OK at the bottom of the Add Operation dialog box. You return to the editor.

CS8661-INTERNET PROGRAMMING LABORATORY 85


6.Remove the default sayhello operation, by deleting the sayhello() method in the source code
7. In code window, type the coding for FeedBacK operation
Two.java
package com.prgguru.example;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
@WebService()
public class two
{
@WebMethod(operationName = "FEEDBACK")
public String FeedBack (@WebParam(name = "Name")
String Name, @WebParam(name = "City")
String City, @WebParam(name = "Comment")
String Comment)
{
int G=0,B=0,P=0;

CS8661-INTERNET PROGRAMMING LABORATORY 86


if(Comment.equals("GooD"))
G=G+1;
else if (Comment.equals("Better"))
B=B+1;
else
P=P+1;
String s="<html><body>NAME :"+Name+ "<br> GooD=
"+String.valueOf(G)+"Better= "+ String.valueOf(B)+"Poor= "+String.valueOf(P);
return s;
}
}
8 Clean & Build the project
9 Deploy the project
10 Expand webservice->right click two webservice ->select Test webservice.Now the output
is displayed on browser window.

CS8661-INTERNET PROGRAMMING LABORATORY 87


10. Procedure to create client application(Client : JSP Page in Web Application)
11. Choose File > New Project .Select Web Application from the Java Web category. Name
the project product. Click Next and then click Finish.
12. Right-click the project and choose New > HTML file generate a feedback form
13. Right-click the Web Pages node and choose New > JSP
14. Right-click the product project and choose New > Web Service Client.
15. Select Project as the WSDL source. Click Browse. Browse to the WC1 web service and
select two service in it, click OK.

16. Do not select a package name. Leave this field empty.


17. Leave the other settings at default and click Finish.
18. The Projects window displays the new web service client
19. In the Web Service References node, expand the node that represents the web service.
The FEEDBACK operation, which you will invoke from the client, is now exposed.Drag
the FEEDBACK operation to the client's process.jsp page, and drop it below the H1 tags.
20. The code for invoking the service's operation is now generated in the process.jsp page.
21. Change the value for the input parameters.
22. Right-click the project and choose Run.

CS8661-INTERNET PROGRAMMING LABORATORY 88


23. The server starts, if it wasn't running already. The application is built and deployed, and
the browser opens, displaying the result:

SAMPLE PROGRAM:

Product.html

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<center>People's Opinion Form</center>
<form name="f1" action="http://localhost:8080/product/process.jsp" method="GET">
Name:<input type="text" name="t1" ><br>
City:<input type="text" name="t2" ><br>
Opinion:
<input type="radio" name="t3" value="GooD">Good

CS8661-INTERNET PROGRAMMING LABORATORY 89


<input type="radio" name="t3" value="Better">Better
<input type="radio" name="t3" value="Poor">Poor
<input type="submit" value="SUBMIT" >
<input type="reset" value="CLEAR" >
</form>
</body>
</html>

Process.jsp

(after adding the service code in this file by dragging )


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<body> <h1>RESULT</h1>
<%-- start web service invocation --%><hr/>
<%
try {
com.prgguru.example.TwoService service = new com.prgguru.example.TwoService();
com.prgguru.example.Two port = service.getTwoPort();
// TODO initialize WS operation arguments here
java.lang.String name =request.getParameter("t1");
java.lang.String city =request.getParameter("t2");
java.lang.String comment = request.getParameter("t3");
// TODO process result here
java.lang.String result = port.feedback(name, city, comment);
out.println("Result = "+result);
} catch (Exception ex) {
// TODO handle custom exceptions here
}
%>
<%-- end web service invocation --%><hr/>
</body>
</html>

CS8661-INTERNET PROGRAMMING LABORATORY 90


OUTPUT:

RESULT:
Thus the web service has been created successfully.

CS8661-INTERNET PROGRAMMING LABORATORY 91

You might also like