Ip Lab Manual CS6512 PDF
Ip Lab Manual CS6512 PDF
Ip Lab Manual CS6512 PDF
LAB MANUAL
Prepared by
Mr.Gopirajan.P.V
Asst Prof / CSE
SYLLABUS
CS6512
L T PC
0 0 3 2
OBJECTIVES:
The student should be made to:
Be familiar with Web page design using HTML/XML and style sheets
Be exposed to creation of user interfaces using Java frames and applets.
Learn to create dynamic web pages using server side scripting.
Learn to write Client Server applications.
Be familiar with the frameworks JSP Strut, Hibernate, Spring
Be exposed to creating applications with AJAX
LIST OF EXPERIMENTS
WEBPAGECONCEPTS
a) Create a web page with the following using HTML
c) 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 the user information from
the XML document.
SOCKETS & SERVLETS
a) Write programs in Java using sockets to implement the following:
i. HTTP request
ii. FTP
iii. SMTP
iv. POP3
b) Write a program in Java for creating simple chat application with datagram sockets and datagram
packets.
c) Write programs in Java using Servlets:
an init parameter key that is appropriate for its servlet IP address and port before it unlocks itself and
handles a request
f) Session tracking using hidden form fields and Session tracking for a hit count.
g) 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.
ADVANCECONCEPTS:
a) Implement a simple program using following frameworks
TOTAL: 45 PERIOD
REFERENCE:
spoken-tutorial.org.
LIST OF EQUIPMENT FOR A BATCH OF 30 STUDENTS: SOFTWARE:
Java, Dream Weaver or Equivalent, MySQL or Equivalent, Apache Server
HARDWARE:
Standalone desktops 30 Nos
EXPT. NO.
1.
2.
Write a webpage that displays college information using various style sheet Style Sheets
3.
Write a DHTML code for creating the web page for validating the web form
4.
5.
Write a java program to create a color palette with the matrix of Buttons
6.
7.
8.
9.
10.
11.
LEARNINGOBJECTIVES
The objective of this lab is to provide a student with an understanding of the fundamental concepts
in internet programming and to provide the skills needed for developing web based application with
Java platform. They can also have knowledge of the underlying generic principles of computer
programming as applied to implementing basic web-based applications.
INTRODUCTION
JAVA Java is one of the most popular programming languages used to create Web applications and
platforms. It was designed for flexibility, allowing developers to write code that would run on any
machine, regardless of architecture or platform. According to the Java home page, more than 1
billion computers and 3 billion mobile phones worldwide run Java.
HTML Hypertext Markup Language (HTML) is the main markup language for creating web pages
and other information that can be displayed in a web browser. HTML is written in the form of HTML
elements consisting of tags enclosed in angle brackets (like <html>), within the web page content.
HTML tags most commonly come in pairs like <h1> and
</h1>, although some tags represent empty elements and so are unpaired, for example
<img>. The first tag in a pair is the start tag, and the second tag is the end tag (they are also called
opening tags and closing tags). In between these tags web designers can add text, further tags,
comments and other types of text-based content.
CSS Cascading Style Sheets, more commonly known by the abbreviation CSS, are style sheets that
are linked to the XHTML (Extensible Hypertext Markup Language) of the website. The CSS code
allows Web developers to take control of many aspects of their site, such as fonts, colors, positioning
and styling of data, while the XHTML code of the site deals with the actual content and structure of
the website.
JAVASCRIPT Javascript is an easy-to-use programming language that can be embedded in the header of
your web pages. It can enhance the dynamics and interactive features of your page by allowing you
to perform calculations, check forms, write interactive games, add special effects, customize graphics
selections, create security passwords and more.
SERVLET The Servlet is a Java programming language class used to extend the capabilities of a
server. Although servlets can respond to any types of requests, they are commonly used to extend
the applications hosted by web servers, so they can be thought of as Java Applets that run on servers
instead of in web browsers. These kinds of servlets are the Java counterpart to other dynamic Web
content technologies such as PHP and ASP.NET.
JSP - Java Server Page: It is a server-side technology; Java Server Pages are an extension to the Java
servlet technology that was developed by Sun.
JSPs have dynamic scripting capability that works in tandem with HTML code, separating the page
logic from the static elements -- the actual design and display of the page -- to help make the HTML
more functional (i.e. dynamic database queries).
A JSP is translated into Java servlet before being run, and it processes HTTP requests and
generates responses like any servlet. However, JSP technology provides a more convenient way to
code a servlet. Translation occurs the first time the application is run. A JSP translator is
triggered by the .jsp file name extension in a URL. JSPs are fully interoperable with servlets. You can
include output from a servlet or forward the output to a servlet, and a servlet can include output from a
JSP or forward output to a JSP.
JSPs are not restricted to any specific platform or server. It was orignially created as an alternative
to Microsoft's ASPs (Active Server Pages). Recently, however, Microsoft has countered JSP
technology with its own ASP.NET, part of the .NET initiative.
AJAX an acronym for Asynchronous JavaScript and XML) is a group of interrelated web development
techniques used on the client-side to create asynchronous web applications. With Ajax, web
applications can send data to, and retrieve data from, a server asynchronously (in the
background) without interfering with the display and behavior of the existing page. Data can be
retrieved using the XMLHttpRequest object. Despite the name, the use of XML is not required (JSON is
often used instead. See AJAJ), and the requests do not need to be asynchronous
www.studentsfocus.com
1
Ex. No: 1
DATE:
IMAGE MAPPING
AIM:
To write a map and fix the hotspots to show the information of
it in a web page.
ALGORITHM:
1. Start the program.
2. Get the india map image and link it to the package.
<img src="flag.jpg">
<img align="right" src = "India Map.gif" usemap="#india">
www.studentsfocus.com
2
Tamiladu.html
<html>
<head>
<body bgcolor="#fggbhjgdhg"/>
<center><h2>it is a tamilnadu,here maximum tamilan living and capital of tamilnadu is
</h2><h1>chennai<h1></center>
</head>
</html>
Kerala.html
<html>
<head>
<body bgcolor="#7674dshddf"/>
<center>it is a kerala,here maximum malaiyalees living and capital of kerala is
<h1>Thiruvananthapuram</h1></center>
</head>
</html>
Karataka.html
<html>
<head>
<body bgcolor="#7674dshddf"/>
<center>it is a karnataka,here maximum kannadam living and capital of karnataka is
<h1>Bangalore</h1></center>
</head>
</html>
Madhyapradesh.html
<html>
<head>
<body bgcolor="blue"/>
<center>it is a madhyapradesh,here maximum maratiyam living and capital of madhyapradesh
is <h1>BHOPAL</h1></center>
</head>
</html>
Maharastra.html
<html>
<head>
<body bgcolor="blue"/>
<center>it is a maharashtra,here maximum maratiyam living and capital of maharashtra is
<h1>Mumbai</h1></center>
</head>
</html>
www.studentsfocus.com
3
Orissa.html
<html>
<head>
<body bgcolor="blue"/>
<center><h2>it is a orissa,here maximum oreya living and capital of orissa is</h2>
<h1>Bhubaneswar</h1></center></head></html>
Output:
www.studentsfocus.com
4
RESULT:
Thus the web page is created and the image is embedded with hot spot and the linking
ages successfully, and the output is verified.
www.studentsfocus.com
5
Ex. No: 2
DATE:
STYLE SHEET
AIM:
To write a webpage that displays college information using various style sheet.
ALGORITHM:
1. Start the program.
2. Create a web page with framesets consisting two frames.
3. In the first frame include the links.
4. In the second frameset display the webpage of the link.
5. Create a external style sheets.
6. Create a inline and internal style and make a link to the external style sheet.
7. Stop the program.
SOURCE CODE:
<html>
<head>
<title>Cascading Style Sheets</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>
<br />
<font face="Arial"size="6">
<a href ="inline.html" style="text-decoration :none;"> 1. Inline Style Sheet</a><br />
<a href ="embedded.html" style="text-decoration :none;"> 2. Embeded Style
Sheet</a><br />
<a href ="external.html" style="text-decoration :none;"> 3. External Style
Sheet</a><br />
<a href ="import.html" style="text-decoration :none;"> 4. Imported Style
Sheet</a><br /></font>
</body>
</html>
Inline.html
<html>
<head>
<title>Inline Style Sheet</title>
</head>
<body>
<ol class="decimal">
<h1 style="font-family :Monotype Corsiva ;background-color:antiquewhite ;"><li>
Inline Style Sheet</li></h1>
<h3>
<p style="text-indent :30pt;color:blue;font-family :arial;">
www.studentsfocus.com
6
www.studentsfocus.com
7
</head>
<body>
<h1>1. Imported Style Sheet</h1>
<h3> Imported style sheet is a shet that can be imported to another sheet.
This alignes exacting one main sheet containing declarations that apply to
the whle site and partial sheets containing declarations that apply to specific
elements.</h3>
</body>
</html>
Output:
www.studentsfocus.com
8
www.studentsfocus.com
9
RESULT:
Thus the web page is created using all tyes of cascading style sheets successfully and the
output is also verified.
www.studentsfocus.com
10
EX. No: 3
DATE:
WEB FORM VALIDATION
AIM:
To write a DHTML code for creating the web page for validating the web form.
ALGORITHM:
1.The form will include one text field called "Your Name", and a submit button.
2.Validation script will ensure that the user enters their name before the form is sent to the
server.
3.Open this page to see it in action.
4.Try pressing the Send Details button without filling anything in the "Your Name" field.
5.You might like to open the source code for this form in a separate window
6.The page consists of a JavaScript function called validate_form() that performs the form
validation, followed by the form itself.
SOURCE CODE:
<html>
<head>
<title>A Simple Form with JavaScript Validation</title>
<script type="text/javascript">
<!-function validate_form ( )
{
valid = true;
if ( document.contact_form.contact_name.value == "" )
{
alert ( "Please fill in the 'Your Name' box." );
valid = false;
}
if(document.contact_form.contact_name.value)
{
alert("Your details had sended");
valid=true;
}
return valid;
}
//-->
</script>
</head>
<body bgcolor=#FFFFFF>
<form name="contact_form" method="post"
action="css.html"
onSubmit="return validate_form();">
<h1>Please Enter Your Name</h1>
<p>Your Name: <input type="text" name="contact_name"></p>
<p><input type="submit" name="send" value="Send Details"></p>
www.studentsfocus.com
11
</form>
</body>
</html>
OUTPUT:
www.studentsfocus.com
12
RESULT:
Thus the program has been written for creating the web page for validating the
informations.
www.studentsfocus.com
13
Ex.No:4
DATE:
APPLET CREATION
AIM:
To write a java program to create the applets.
ALGORITHMS:
1.Write a HTML applet tag with code set, class name, and comment the tag.
2.Import all necessary packages and classes.
3.Define a class that extends applet and implements action listener and item listener.
4.Declare an array of buttons to set colors , two check boxes for foreground and
background colors.
5.Declare a text area to hold the text, a check box group for check boxes.
6. Declare three panels, button panel, palette panel and check pael.
7. Declare a string, color.
8.Display the result.
9.Stop the program.
SOURCE CODE:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
/*<applet code=colour.class height=200 width=200>
</applet>*/
public class colour extends JApplet implements ActionListener
{
JPanel p,p1;
JButton b,b1,b2,b3;
Checkbox c,c1;
TextArea area;
Color d=new Color(255,0,0);
Color d1=new Color(0,255,0);
Color d2=new Color(0,0,255);
Color d3=new Color(255,177,76);
GridLayout g;
public void init()
{
p=new JPanel();
p1=new JPanel();
g=new GridLayout(2,2);
p1.setLayout(g);
b=new JButton();
b1=new JButton();
www.studentsfocus.com
14
b2=new JButton();
b3=new JButton();
b.setBackground(d);
b1.setBackground(d1);
b2.setBackground(d2);
b3.setBackground(d3);
area=new TextArea(" Welcome To Colour Palate ",25,25);
CheckboxGroup cbg=new CheckboxGroup();
c=new Checkbox(" ForeGround ",cbg,true);
c1=new Checkbox(" BackGround ",cbg,false);
p.add(c);
p.add(c1);
p.add(area);
p1.add(b);
p1.add(b1);
p1.add(b2);
p1.add(b3);
p.add(p1);
getContentPane().add(p);
b.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
Object obj=e.getSource();
if(obj==b)
{
if(c.getState()==true)
area.setForeground(d);
else
area.setBackground(d);
}
if(obj==b1)
{
if(c.getState()==true)
area.setForeground(d1);
else
area.setBackground(d1);
}
if(obj==b2)
{
if(c.getState()==true)
area.setForeground(d2);
else
www.studentsfocus.com
15
area.setBackground(d2);
}
if(obj==b3)
{
if(c.getState()==true)
area.setForeground(d3);
else
area.setBackground(d3);
}}}
OUTPUT:
www.studentsfocus.com
16
www.studentsfocus.com
17
Ex. No: 5
DATE:
COLOR PALETTE.
AIM:
x
x
x
x
x
x
To write a java program to create a color palette with the matrix of Buttons.
Set the background and foreground of the control unit area
By selecting a color from color palette.
In order to select foreground (or) background are checkbox
Control as radio buttons.
To set background images.
ALGORITHM:
1. Import the package that are necessary to create an palette color.
2. Allocate memory location for buttons and checkbox group by Using new keyword.
3. Set the background and by using the background.
4. Add the component color by using add method.
5. Call the methods for listening the action.
6. The getimage method is used to get the image and displayed Onto the screen.
7. Compile and run the program.
SOURCE CODE:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<Applet code="colorpl" height=600 width=600></applet>*/
public class colorpl extends Applet implements ItemListener
{
int currcolor=5;
int flag=1;
String text="click any of the button";
Button buttons[]=new Button[5];
String colors[]={"red","blue","green","yellow","magenta"};
Image img;
CheckboxGroup cbg=new CheckboxGroup();
Checkbox box1=new Checkbox("Background color",cbg,true);
Checkbox box2=new Checkbox("Text color",cbg,false);
Checkbox box3=new Checkbox("Loading Image", cbg, false);
public void init()
{
for(int i=0;i<5;i++)
{
buttons[i]=new Button(" ");
add(buttons[i]);
}
buttons[0].setBackground(Color.red);
buttons[1].setBackground(Color.blue);
www.studentsfocus.com
18
buttons[2].setBackground(Color.green);
buttons[3].setBackground(Color.yellow);
buttons[4].setBackground(Color.magenta);
add(box1);
add(box2);
add(box3);
box1.addItemListener(this);
box2.addItemListener(this);
box3.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
if(box1.getState()==true)
flag=1;
if(box2.getState()==true)
{
text="default color is Black";
flag=2;
}
if(box3.getState()==true)
{
img=getImage(getDocumentBase(),"jelly.bmp);
flag=3;
}
repaint();
}
public void paint(Graphics g)
{
if(flag==2)
{
g.drawString(text,30,100);
switch(currcolor)
{
case 0:
g.setColor(Color.red);
break;
case 1:
g.setColor(Color.blue);
break;
case 2:
g.setColor(Color.green);
break;
case 3:
g.setColor(Color.yellow);
break;
case 4:
www.studentsfocus.com
19
g.setColor(Color.magenta);
break;
case 5:
g.setColor(Color.black);
break;
}
g.drawString(text,30,100);
}
else if(flag==1)
{
g.drawString(text,30,100);
switch(currcolor)
{
case 0:
setBackground(Color.red);
break;
case 1:
setBackground(Color.blue);
break;
case 2:
setBackground(Color.green);
break;
case 3:
setBackground(Color.yellow);
break;
case 4:
setBackground(Color.magenta);
break;
case 5:
setBackground(Color.white);
break;
}
g.drawString(text,30,100);
}
else if(flag==3)
{
g.drawImage(img,20,90,this);
}}
public boolean action(Event e,Object o)
{
for(int i=0;i<5;i++)
{
if(e.target==buttons[i])
{
currcolor=i;
text="you have chosen" +colors[i];
www.studentsfocus.com
20
repaint();
return true;
}}
return false;
}}
OUTPUT:
www.studentsfocus.com
21
RESULT:
Thus the java program for color palette was executed and verified.
www.studentsfocus.com
22
Ex. No: 6A
DATE:
www.studentsfocus.com
23
out.println("<HEAD>");
out.println("<TITLE>");
out.println("ServletResponse");
out.println("</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("<B>Demonstrating the ServletResponse object</B>");
out.println("<BR>");
out.println("<BR>Server Port: " + request.getServerPort());
out.println("<BR>Server Name: " + request.getServerName());
out.println("<BR>Protocol: " + request.getProtocol());
out.println("<BR>Character Encoding: " + request.getCharacterEncoding());
out.println("<BR>Content Type: " + request.getContentType());
out.println("<BR>Content Length: " + request.getContentLength());
out.println("<BR>Remote Address: " + request.getRemoteAddr());
out.println("<BR>Remote Host: " + request.getRemoteHost());
out.println("<BR>Scheme: " + request.getScheme());
Enumeration parameters = request.getParameterNames();
while (parameters.hasMoreElements()) {
String parameterName = (String) parameters.nextElement();
out.println("<br>Parameter Name: " + parameterName);
out.println("<br>Parameter Value: " +
request.getParameter(parameterName));
}
Enumeration attributes = request.getAttributeNames();
while (attributes.hasMoreElements()) {
String attribute = (String) attributes.nextElement();
out.println("<BR>Attribute name: " + attribute);
out.println("<BR>Attribute value: " + request.getAttribute(attribute));
}
out.println("</BODY>");
out.println("</HTML>");
}
public String getServletInfo() {
return null;
}
publicServletConfiggetServletConfig() {
return null;
}
}
www.studentsfocus.com
24
OUTPUT:
RESULT:
Thus the program for invoking servlet from HTML form was executed and the output
was verified.
www.studentsfocus.com
25
Ex. No 6B
DATE:
www.studentsfocus.com
26
HttpServletResponse response)
throwsServletException, IOException {
String userName = request.getParameter("userName");
String password = request.getParameter("password");
if (userName!=null && password!=null &&
userName.equals("jamesb") &&password.equals("007")) {
RequestDispatcherrd = request.getRequestDispatcher("WelcomeServlet");
rd.forward(request, response);
}else {
sendLoginForm(response, true);
} }}
Response Page for Login:
importjavax.servlet.*;
importjavax.servlet.http.*;
import java.io.*;
public class WelcomeServlet extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>Welcome</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("<P>Welcome to the Bulbul's and Boni's Web Site.</P>");
out.println("</BODY>");
out.println("</HTML>");
}
}
www.studentsfocus.com
27
OUTPUT:
RESULT:
Thus the program for login page and its response was done successfully and the output
was verified.
www.studentsfocus.com
28
Ex. No: 7
DATE:
ONLINE EXAMINATION
AIM:
To write the JSP program for online examination.
ALGORITHM:
1. Start the program.
2. With the scriplet tag, include information like document
Created on and author.
3. Set the content type using page content type=txt\html.
4. Include the doctype with transitional flavour.
5. Get the input as regno , name and store in the table.
6. Create the forms as exam and index.
7. Click the submit button, after completing all the
questions. If the answers are correct it will display
as correct else incorrect.
8. Stop the program.
SOURCE CODE:
Newjsp.jsp:
<%-Document : exam
Created on : Feb 23, 2011, 7:19:15 PM
Author : A
--%>
<%@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>Examination Panel</title>
</head>
<body bgcolor="cyan">
<%@ page language="java" %>
<%@ page import ="java.sql.*" %>
<%
String reg= request.getParameter("txt_reg");
String name = request.getParameter("txt_name");
out.println("<h2>Welcome" + name + "...Your Register number is " + reg +
"!!</h2><br><br><br>");
www.studentsfocus.com
29
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String sTable = "exam";
String sSql = "SELECT * FROM " + sTable + "";
String database = "jdbc:odbc:sDBQ";
Connection cn = null;
Statement st = null;
ResultSet rs = null;
try {
cn = DriverManager.getConnection( database ,"sa","");
st = cn.createStatement();
rs = st.executeQuery( sSql );
ResultSetMetaData rsmd = rs.getMetaData();
String s1,s2,s3,s4;
int i=1;
while(rs.next())
{
out.println("<form name='exam' action='newjsp2.jsp' method='post'><b>"+i+" . " +
rs.getString(1) + "</b><br><br>");
s1 = rs.getString(2);
s2 = rs.getString(3);
s3 = rs.getString(4);
s4 = rs.getString(5);
out.println("<input type=radio name=opt"+i+" value="+s1+" CHECKED>"+ s1 +" <br><br>");
out.println("<input type=radio name=opt"+i+" value="+s2+">" + s2 +"<br><br>");
out.println("<input type=radio name=opt"+i+" value="+s3+">" + s3 +"<br><br>");
out.println("<input type=radio name=opt"+i+" value="+s4+">" + s4 +"<br><br>");
i++;
}
out.println("<input name ='submit' value='Submit' type='submit'/>");
/*int n = rsmd.getColumnCount();
out.println( "<table border=1 cellspacing=3><tr>" );
for( int i=1; i<=n; i++ ) // Achtung: erste Spalte mit 1 statt 0
out.println( "<th>" + rsmd.getColumnName( i ) + "</th>" );
while( rs.next() )
{out.println( "</tr><tr>" );
for( int i=1; i<=n; i++ ) // Achtung: erste Spalte mit 1 statt 0
o ut.println( "<td nowrap>" + rs.getString( i ) + "</td>" );
}
out.println( "</tr></table>" );*/
}finally {
try { if( null != rs ) rs.close(); } catch( Exception ex ) {}
try { if( null != st ) st.close(); } catch( Exception ex ) {}
try { if( null != cn ) cn.close(); } catch( Exception ex ) {}
}
%>
</body>
</html>
www.studentsfocus.com
30
Newjsp1.jsp
<%-Document : index
Created on : Feb 9, 2011, 6:50:54 PM
Author : A
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome to Online Examination</title>
</head>
<body bgcolor="cyan">
<form name="index" action="newjsp.jsp" method="post">
<center><h1><span><font color="red">Welcome to Online
Examination</font></span></h1>
<br>
<h2><u><span><font color="blue">Instructions to the
Candidates</font></span></u></h2>
<br><h3><ol><li>Fill the correct Registration number.</li>
<br><li>Enter your name.</li>
<br><li>Read the questions carefully.</li>
<br><li>No negative marking.</li></ol></h3>
<br>
<b>Enter your Register number</b>
<input type="text" name="txt_reg">
<b>Enter your Name</b>
<input type="text" name="txt_name"><br><br>
<input name ="submit" value="Submit" type="submit"/>
</center>
</form>
</body>
</html>
Newjsp2.jsp
<%-Document : report
Created on : Feb 23, 2011, 9:09:37 PM
Author : A
--%>
<%@page import="com.sun.java.swing.plaf.windows.resources.windows_es"%>
www.studentsfocus.com
31
www.studentsfocus.com
32
i++;
}
out.println("</table><br><br><table><b><tr><td>Correct
Answers</td><td>"+correct+"</td></tr>");
out.println("<tr><td>Incorrect Answers</td><td>"+incorrect+"</td></tr>");
out.println("<tr><td>Total
Questions</td><td>"+total+"</td></tr></table></b></center></h2>");
}
finally {
try { if( null != rs ) rs.close(); } catch( Exception ex ) {}
try { if( null != st ) st.close(); } catch( Exception ex ) {}
try { if( null != cn ) cn.close(); } catch( Exception ex ) {}
}
%>
</body>
</html>
www.studentsfocus.com
33
OUTPUT:
www.studentsfocus.com
34
RESULT:
Thus the JSP program for online examination was executed by connecting the SQLSERVER
and result was verified
www.studentsfocus.com
35
Ex. No: 8
AIM:
To write a XML scheme to generate CD Collection details
ALGORITHM:
Step 1: Start the program
Step 2: Use Xml Style Sheet code to define link
<?xml-stylesheet type="text/xsl" href="yourxsl.xsl"?>
Step 3: Use the catalog tag to define CD collection details.
Step 4: Use the necessary heading for appropriate XML tag.
Step 5: Provide necessary information for CD collection details
Step 6: Stop the program
SOURCE CODE:
Username.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy -->
<?xml-stylesheet type="text/xsl" href="yourxsl.xsl"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
<cd>
www.studentsfocus.com
36
DATE:
www.studentsfocus.com
37
</cd>
<cd>
<title>When a man loves a woman</title>
<artist>Percy Sledge</artist>
<country>USA</country>
<company>Atlantic</company>
<price>8.70</price>
<year>1987</year>
</cd>
<cd>
<title>Black angel</title>
<artist>Savage Rose</artist>
<country>EU</country>
<company>Mega</company>
<price>10.90</price>
<year>1995</year>
</cd>
<cd>
<title>1999 Grammy Nominees</title>
<artist>Many</artist>
<country>USA</country>
<company>Grammy</company>
<price>10.20</price>
<year>1999</year>
</cd>
<cd>
<title>For the good times</title>
<artist>Kenny Rogers</artist>
<country>UK</country>
<company>Mucik Master</company>
<price>8.70</price>
<year>1995</year>
</cd>
<cd>
<title>Big Willie style</title>
<artist>Will Smith</artist>
<country>USA</country>
<company>Columbia</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>Tupelo Honey</title>
<artist>Van Morrison</artist>
<country>UK</country>
<company>Polydor</company>
www.studentsfocus.com
38
<price>8.20</price>
<year>1971</year>
</cd>
<cd>
<title>Soulsville</title>
<artist>Jorn Hoel</artist>
<country>Norway</country>
<company>WEA</company>
<price>7.90</price>
<year>1996</year>
</cd>
<cd>
<title>The very best of</title>
<artist>Cat Stevens</artist>
<country>UK</country>
<company>Island</company>
<price>8.90</price>
<year>1990</year>
</cd>
<cd>
<title>Stop</title>
<artist>Sam Brown</artist>
<country>UK</country>
<company>A and M</company>
<price>8.90</price>
<year>1988</year>
</cd>
<cd>
<title>Bridge of Spies</title>
<artist>T`Pau</artist>
<country>UK</country>
<company>Siren</company>
<price>7.90</price>
<year>1987</year>
</cd>
<cd>
<title>Private Dancer</title>
<artist>Tina Turner</artist>
<country>UK</country>
<company>Capitol</company>
<price>8.90</price>
<year>1983</year>
</cd>
<cd>
<title>Midt om natten</title>
<artist>Kim Larsen</artist>
www.studentsfocus.com
39
<country>EU</country>
<company>Medley</company>
<price>7.80</price>
<year>1983</year>
</cd>
<cd>
<title>Pavarotti Gala Concert</title>
<artist>Luciano Pavarotti</artist>
<country>UK</country>
<company>DECCA</company>
<price>9.90</price>
<year>1991</year>
</cd>
<cd>
<title>The dock of the bay</title>
<artist>Otis Redding</artist>
<country>USA</country>
<company>Atlantic</company>
<price>7.90</price>
<year>1987</year>
</cd>
<cd>
<title>Picture book</title>
<artist>Simply Red</artist>
<country>EU</country>
<company>Elektra</company>
<price>7.20</price>
<year>1985</year>
</cd>
<cd>
<title>Red</title>
<artist>The Communards</artist>
<country>UK</country>
<company>London</company>
<price>7.80</price>
<year>1987</year>
</cd>
<cd>
<title>Unchain my heart</title>
<artist>Joe Cocker</artist>
<country>USA</country>
<company>EMI</company>
<price>8.20</price>
<year>1987</year>
</cd>
</catalog>
www.studentsfocus.com
40
yourxsl.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<xsl:sort select="artist"/>
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
RESULT:
Thus the XML scheme to generate CD Collection details was executed successfully
and verified.
www.studentsfocus.com
41
Ex. No 9
DATE:
AJAX.
AIM:
To write a java script program for a AJAX.
ALGORITHM:
1. Start the program.
2. A scripting language that is commonly hosted in a browser to add
Interactivity to HTML PAGES.
3. Defines the structure of a webpage as a set of programmable objects
that can be accessed through javascript.
4. Allows a client-side script to perform and httprequest.
5. AJAX applications use xmlhttprequest object to perform asynchronous
requests to the server as opposed to performing a full page refresh.
6. Display the result.
7. Stop the program.
PROGRAM:
<html>
<head>
<script type="text/javascript">
functionloadXMLDoc()
{
if (window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
else
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 &&xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","new.txt",true);
xmlhttp.send();
}
</script>
<title>ajax program</title>
</head>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</body>
www.studentsfocus.com
42
</html>
New.txt:
WELCOME!!!
OUTPUT:
RESULT:
Thus the program for AJAX was executed and the output was verified.
www.studentsfocus.com
43
EX.NO: 10
DATE:
www.studentsfocus.com
44
}
else if (element ==-1 && input == 2)
{
document.writeln("The Economy Class is already fully
booked<br/>");
secondQuestion(seats);
}
else
boarding Pass(input);
}
//to terminate the program
else
{
window.status="Bye-bye!";
System.exit(0);
}
}
}
function linear Search(the Array)
{
if (input == 1)
{
for (var n=0; n<6 ; n++)
if (the Array [n] == 0)
return n;
}
else if (input == 2)
{
for (var n=6; n<11 ; n++)
if (the Array [n] == 0)
return n;
}
return -1;
}
function boarding Pass(the Input)
{
if (input ==1)
{
document.writeln("----------BOARDING PASS----------<br/>");
document.writeln("You are allocated in the First Class<br/>");
document.writeln("Your seat number is "+ element+"<br/>");
document.writeln("-----------------------------------------<br/>");
seats[element]= 1;
firstCount++;
}
else if (input ==2)
www.studentsfocus.com
45
{
document.writeln("----------BOARDING PASS----------<br/>");
document.writeln("You are allocated in the EconomyClass<br/>"); document.writeln("Your
seat
number is "+ element +"<br/>");
document.writeln("-----------------------------------------<br/>");
seats[element]= 1;
economyCount++;
}
}
functionsecondQuestion(theArray)
{
if (input == 1)
{
for (var n=6; n<11 ;n++)
{
if (theArray [n] == 0)
{
second Input = window.prompt("Do you want to move to Economy Class?
(If YES, please press 1. If NO, please press 2)","0");
if ( second Input == 1)
{
input = 2;
element=linear Search(seats);
document.writeln("You have been allocated to Economy
Class<br/>");
boardingPass(input);
break;
}
else if (secondInput == 2)
{
document.writeln("Next flight leaves in 3 hours<br/>"); break;
}
}
}
}
else if (input == 2)
{
for (var n=0; n<6 ;n++)
{
if (theArray [n] == 0)
{
secondInput = window.prompt("Do you want to move to First Class? (If YES,
please press 1. If NO, please press 2)","0");
for (var n=0; n<6 ;n++)
{
www.studentsfocus.com
46
if (theArray [n] == 0)
{
secondInput = window.prompt("Do you want to move to First Class? (If YES, please press 1. If
NO, please press 2)","0");
boarding Pass(input); break;
}
else if (secondInput == 2)
{
document.writeln("Next flight leaves in 3 hours<br/>");
break;
}
}}
}
}
//-->
</script>
</head>
<body onload = "startArray()"></body>
</html>
www.studentsfocus.com
47
OUTPUT:
RESULT:
Thus the program is executed and verified successfully.
www.studentsfocus.com
48