EX.NO: 1 EMBEDDING AN IMAGE MAP
DATE:
Aim:
To write a program to implement image mapping technique using html
Algorithm:
Algorithm:
Step 1: Start the program
Step 2: Create a html program which embed a image
Step 3: Create a map using map tag
Step 4: Specify the co-ordinates of the image
Step 5: use the map in the image tag
Step 6: Close the html file.
CODING:
imageMap1.html
imageMap1.html
<html>
<body>
<p>Image Map-PICTURE</p>
<img src="Winter.jpg" width="245" height="226" alt="Planets"
usemap="#planetmap"/>
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.html" />
<area shape="circle" coords="90,58,3" alt="Mercury" href="mercury.html" />
<area shape="circle" coords="124,58,8" alt="Venus" href="venus.html" />
</map>
</body>
</html>
sun.html
<html>
<body>
Sun welcomes you......
</body>
</html>
mercury.html
<html>
<body>
mercury welcomes you......
</body>
</html>
venus.html
<html>
<body>
venus welcomes you......
</body>
</html>
OUTPUT:
RESULT:
Thus the program for image mapping is successfully executed and output is verified.
EX.NO: 2 CASCADING STYLE SHEETS
DATE:
Aim:
To write a program for implementing the style sheet
Algorithm:
STEP 1: Start the program
STEP 2: In simple selector, normal style is used.
STEP 3: In class selector, use predefined tag name with dot extension for implementing in style sheet and use it in body section.
STEP 4: In generic selector, use dot extension for implementing in style sheet and use in body section
STEP 5: In id selector, use predefined tag name with hash extension for implementing in style sheet and use in body section
STEP 6: In pseudo selector, write different colors for visited, active, hover, link in style sheet and use in body section
STEP 7: Stop the program.
CODING:
CODING:
main.html
<html>
<body>
Types of CSS
<a href="InlineCSS.html" target="_blank">Inline</a>
<a href="InternalCSS.html" target="_blank">Internal</a>
<a href="ExternalCSS.html" target="_blank">External</a>
</body>
</html>
InlineCSS.html
<html>
<body>
<div id="container" style="width:1000px">
<div id="header" style="background-color:brown;">
<h1 style="margin-bottom:0;">Main Title of Web Page for INLINE CSS
</h1>
</div>
<div id="menu" style="background-color:yellow;height:500px;width:400px;float:left;">
<b>Menu</b><br />
HTML<br />
CSS<br />
JavaScript
</div>
<div id="content" style="background-color:white;height:200px;width:600px;float:left;">
Content goes here
</div>
<div id="footer" style="background-color:brown;clear:both;text-align:center;">
Copyright © 2011 W3Schools.com
</div>
</div>
</body>
</html>
InternalCSS.html
<html>
<head>
<style type="text/css">
#container
{
width:1000px
}
#header
{
background-color:brown;
}
h1
{
margin-bottom:0;
}
#menu
{
background-color:yellow;
height:500px;
width:400px;
float:left;
}
#content
{
background-color:white;
height:200px;
width:600px;
float:left;
}
#footer
{
background-color:brown;
clear:both;
text-align:center;
}
</head>
</style>
<body>
<div id="container">
<div id="header">
<h1>Main Title of Web Page for INTERNAL CSS</h1>
</div>
<div id="menu">
<b>Menu</b><br />
HTML<br />
CSS<br />
JavaScript
</div>
<div id="content">
Content goes here
</div>
<div id="footer">
Copyright © 2011 W3Schools.com
</div>
</div>
</body>
</html>
ExternalCSS.html
<html>
<link href="style2.css" rel="stylesheet" type="text/css">
<body>
<div id="container">
<div id="header">
<h1>Main Title of Web Page for EXTERNAL CSS</h1>
</div>
<div id="menu">
<b>Menu</b><br />
HTML<br />
CSS<br />
JavaScript
</div>
<div id="content">
Content goes here
</div>
<div id="footer">
Copyright © 2011 W3Schools.com
</div>
</div>
</body>
</html>
Style2.css
#container
{
width:1000px;
}
#header
{
background-color:brown;
}
h1
{
margin-bottom:0;
}
#menu
{
background-color:yellow;
height:500px;
width:400px;
float:left;
}
#content
{
background-color:white;
height:200px;
width:600px;
float:left;
}
#footer
{
background-color:brown;
clear:both;
text-align:center;
}
OUTPUT:
Main.html
InlineCSS.html
Main.html
InlineCSS.html
InternalCSS.html
ExternalCSS.html
RESULT:
Thus the above program is successfully executed.
EX.NO: 3 CLIENT SIDE SCRIPT FOR VALIDATING WEB FORM
DATE:
AIM:
To display a student registration form in browser and validate its fields before submitting.
ALGORITHM:
STEP 1: Start the program
STEP 2: Design a form with the required fields.
STEP 3: Get the values entered in the form in a java script using the id attributed given in the form.
STEP 4: Check whether all the fields are entered.
STEP 5: Check whether the password retyped is same as the already entered one.
STEP 6: Check whether the age is not less than 10 and not greater than 27.
STEP 7: Check for a valid e-mail id by considering the positions of ‘.’ and ‘@’ characters.
STEP 8: Check whether the phone number field is of correct length and has only numbers.
STEP 9: If any one of the above conditions fail ask the user to refill the form.
STEP 10: Otherwise, register the student.
STEP 11: Stop the program.
CODING:
valiform.html
Registration Form
Video Output:
RESULT:
RESULT:
Thus the program for form validation using javascript is successfully executed and output is verified.
EX.NO: 04 COLOR PALETTES BY APPLET PROGRAM
DATE:
Aim:
To write a applet program for changing background color, image and text color.
Algorithm:
STEP 1: Start the program.
STEP 2: Create an array of button objects.
STEP 3: Create an array of strings that has colors.
STEP 4: Create a checkbox group with 3 check boxes.
STEP 5: Add the buttons and set the background color.
STEP 6: Add the boxes
STEP 7: Register the events
STEP 8: Define the item state Change method
i. If the first checkbox is clicked, the flag 1 is set.
ii. If the second checkbox is clicked, the flag 2 is set.
iii. If the third checkbox is clicked, the flag 3 is set.
STEP 9: Define the paint method.
i. If flag=1, then set the chosen color to be the background using set back ground method.
ii. If flag=2, then set the chosen color to the text color using the set Color method.
iii. If flag=3, then set the heading as image.
STEP 10: Stop the program.
CODING:
Experiment3.java
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="Experiment3" width=50 height=50>
</applet>
*/
public class Experiment3 extends Applet implements ItemListener
{
int currcolor=5;
int flag=1;
int i;
String text="click any of button";
Button buttons[]= new Button[5];
String colours[]={"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(i=0;i<5;i++)
{
buttons[i]=new Button(" ");
add(buttons[i]);
}
buttons[0].setBackground(Color.red);
buttons[1].setBackground(Color.blue);
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 ev)
{
if(box1.getState()==true)
flag=1;
else if(box2.getState()==true)
{
text="Default color is black";
flag=2;
}
else if(box3.getState()==true)
{
img=getImage(getDocumentBase(),"Water lilies.jpg");
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:
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.black);
break;
}
}
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"+colours[i];
repaint();
return true;
}
}
return false;
}
}
OUTPUT:
Thus the program is successfully executed and output is verified.
EX.NO: 5(a) HTML TO SERVLET PROGRAM
DATE:
Aim:
To write a HTML servlet program.
Algorithm:
Step1: Start the program
Step2: Write the html servlet program and save it in java files.
Step3: Write the xml program and Save it with the extension filename.xml
Step 4: Write the html program and save it as filename.html
Step 5: Stop the program.
CODING:
Addition.html:
<html>
<head>
<title> Addtion of Two Numbers </title>
<body>
<form action = Addtion methed = "GET">
firstnumber <input type =text size =20 name =firstnumber>
second number <input type =text size =20 name =secondnumber>
<input type = submit value = "submit">
</body>
</head>
</html>
Addition.java:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Addtion extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String fname = request.getParameter("firstnumber");
String sname = request.getParameter("secondnumber");
int fno = Integer.valueOf(fname );
int sno =Integer.valueOf(sname);
out.println("Addtion totel No:");
out.println( fno+sno);
}
}
Web.xml:
<? xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>
Addtion
</servlet-name>
<servlet-class>
Addtion
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
Addtion
</servlet-name>
<url-pattern>
/Addtion
</url-pattern>
</servlet-mapping>
</web-app>
OUTPUT:
RESULT:
Thus the program using html servlet is successfully executed and the output is verified.
EX.NO: 5(b) APPLET TO SERVLET PROGRAM
DATE:
Aim:
To write a applet to servlet program.
Algorithm:
Step1: Start the program
Step2: Write the servlet example program and save it in java
Step3: Write the xml in program and save in the file with extension filename.xml
Step 4: Save the AppletServletExample in java files
Step 5: Stop the program.
CODING:
Home.html:
<html>
<body>
<h1>Java Applet Demo</h1>
<applet code=AppletCallingServlet.class width=500 height=500>
</applet>
</body>
</html>
AppletCallingServlet.java
import java.io.*;import java.awt.*;
import java.net.*;
import java.applet.*;
public class AppletCallingServlet extends Applet
{
URL url = null;
URLConnection servletConnection = null;
public void init()
{
try{
url = new URL("http://localhost:8080/ServletExample/ServletExample");
servletConnection = url.openConnection();
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
servletConnection.setUseCaches(false);
servletConnection.setDefaultUseCaches(false);
servletConnection.setRequestProperty("Content-Type","application/octet-stream");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void paint(Graphics g)
{
try
{
ObjectInputStream input = new ObjectInputStream(servletConnection.getInputStream());
g.drawString("Applet Servlet Communication",50,50);
String str = new String();
str = (String)input.readObject();
g.drawString(" Message sent from server: " + str,50,100);
input.close();
}
catch( Exception e)
{
e.printStackTrace();
}
}
}
ServletExample.java:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ServletExample extends HttpServlet
{
public void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException , IOException
{
ObjectOutputStream output = null;
try
{
output = new ObjectOutputStream(response.getOutputStream());
String str = new String("Hello World");
output.writeObject(str);
output.flush();
output.close();
System.out.println("Message is===== " + str);
}
catch( Exception e)
{
e. printStackTrace();
}
}
}
Web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>
ServletExample
</servlet-name>
<servlet-class>
ServletExample
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>
ServletExample
</servlet-name>
<url-pattern>
/ServletExample
</url-pattern>
</servlet-mapping>
</web-app>
OUTPUT:
RESULT:
Thus the program using applet to servlet is successfully executed and the output is verified.
EX.NO: 6 Online Examination Using JSP
DATE:
Aim:
To write java server page programs to conduct online examination and to display student mark list available in a database.
Algorithm:
Client:
Step 1: In index.html on the client side declare the contents that you like to transfer to the server using html form and input type tags.
Step 2: create a submit button and close all the included tags.
Servlet:
Step 1: Import all necessary packages
Step 2: Define a class that extends servlet
Step 3: In the do Post() method, do the following:
i) Set the content type of the response to "text/html"
ii) Create a writer to the response
iii) Get a parameter from the request
iv) If its value is equal to right answer then add 5 to mark variable
v) Similarly repeat step
vi) for all parameters
vii) Display the result in an html format using the writer
PROGRAM:
onlineExam.html
<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;
}
return true;
}
</script>
</head>
<body bgcolor=lightgreen>
<h1 align="left">OnLine Examination</h1>
<form action="Exam.jsp"method="post"name="entry"onSubmit="return validation(this)">
<div align="left">
<input type="hidden"value="list"name="action">
<table>
<tr>
<td><h3>Seat Number:</h3></td>
<td><input type="text" name="Seat_no"size="50"></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>
</table>
</div>
<hr align="left"/>
<div align="left"><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 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.HTTpP is statefull protocol.</b><br/>
<input type="radio"name="group5"value="true">
True
<input type="radio"name="group5"value="false">
false<br>
</div>
<hr align="left"/>
<div align="left">
<input type="submit"value="Submit">
<input type="reset" value="clear">
<br>
<br>
</div>
</form>
</html>
Exam.jsp:
<%@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;
Statement stmt = null;
ResultSet rs = null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:studentDB1";
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("false"))
a2 = 2;
else
a2 = 0;
ans3 = request.getParameter("group3");
if (ans3.equals("false"))
a3 = 2;
else
a3 = 0;
ans4 = request.getParameter("group4");
if (ans4.equals("true"))
a4 = 2;
else
a4 = 0;
ans5 = request.getParameter("group5");
if (ans5.equals("false"))
a5 = 2;
else
a5 = 0;
int Total = a1 + a2 + a3 + a4 + a5;
stmt = connect.createStatement();
String query = "INSERT INTO StudentTable(Seat_no,Name1,Marks)VALUES('" +
SeatNum + "','" + Name + "','" + Total + "')";
int result = stmt.executeUpdate(query);
stmt.close();
stmt = connect.createStatement();
query = "SELECT*FROM StudentTable WHERE Name1='"+Name+"'";
rs = stmt.executeQuery(query);
%>
<html><head><title>Student Mark List</title></head>
<body bgcolor=khaki>
<center>
<h2>Students Marksheet</h2>
<h3>Name of the college:sri ram engg college</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>
<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()%></b></td></tr>
<tr><td><b>Signature:X.Y.Z.</b></td></tr>
</table>
<div>
<a href="onlineExam.html">click here to go back</a>
</div>
</body>
</html>
<%} else {%>
<%}%>
Database(Database1.mdb) –DSN CONNECTION(studentDB1)
RESULT:
Thus the program was successfully executed and the output was verified.
EX.NO: 7(a) SIMPLE XML PROGRAM
DATE:
AIM:
To write a XML code to display the details in the HTML format using SAX.
ALGORITHM:
Step1: Start the program
Step2: Initialize the xml version and encoding format
Step3: Set the element information.
Step 4: Initialize all the details to PC data.
Step 5: Stop the program.
CODING:
<?xml version="1.0"?>
<student>
<name>SHARAN</name>
</student>
OUTPUT:
Thus the program was successfully executed and the output was verified.
EX.NO: 7(b) PROGRAM USING XML - XSLT
DATE:
AIM:
AIM:
To implement XSLT in XML document.
ALGORITHM:
STEP 1: Start the program.
STEP 2: Create an XML document with the details of the student such as name, address, standard and mark.
STEP 3: Import an XSL file to the xml file.
STEP 4: The XSL file imported puts the details of the students given in the xml file in a table and gets the details of each student from the xml file using the value-of attribute.
STEP 5: The output in the browser would be the details from the XML file with the style specified in XSL applied to it.
STEP 6: Stop the program.
PROGRAM:
Info.XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="detail.xsl"?>
<student>
<personal_info>
<name>priya</name>
<addr>avadi</addr>
<std>3rd yr</std>
<mark>85</mark>
</personal_info>
<personal_info>
<name>mathi</name>
<addr>tirutani</addr>
<std>3rd yr</std>
<mark>75</mark>
</personal_info>
<personal_info>
<name>reshma</name>
<addr>egmore</addr>
<std>3rd yr</std>
<mark>80</mark>
</personal_info>
<personal_info>
<name>dilshad</name>
<addr>pattalam</addr>
<std>3rd yr</std>
<mark>88</mark>
</personal_info>
</student>
Detail.XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body bgcolor="pink">
<center><h2>student database</h2></center>
<center>
<table bgcolor="aqua" border="7" width="650" height="400">
<tr>
<th>name</th>
<th>addr</th>
<th>std</th>
<th>mark</th>
</tr>
<xsl:for-each select="student/personal_info">
<xsl:sort select="mark"/>
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="addr"/></td>
<td><xsl:value-of select="std"/></td>
<td><xsl:value-of select="mark"/></td>
</tr>
</xsl:for-each>
</table>
</center>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
OUTPUT:
RESULT:
Thus the program for XSLT XML schema is successfully executed and output is verified.
EX.NO: 8(a) PROGRAM USING DOM WITH XML
DATE:
Aim:
To write a program using SAX along with XML file.
Algorithm:
Step 1: Start the program
Step 2: Keep the xml and java file in the same folder.
Step 3: Import the required packages initially.
Step 4: Use Buffer Reader to read the contents from the command prompt.
Step 5: Get the name of the xml file from the user to execute.
Step 6: Using XML Reader Factory obtain the parser.
Step 7: If the document is correctly parsed then print document is well formed else print document is not well formed.
CODING:
Parsing_DOMDemo.java:
import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
public class Parsing_DOMDemo
{
static public void main(String[] arg)
{
try
{
System.out.print("Enter the name of XML document ");
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String file_name = input.readLine();
File fp = new File(file_name);
if(fp.exists())
{
try
{
DocumentBuilderFactory Factory_obj = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = Factory_obj.newDocumentBuilder();
InputSource ip_src = new InputSource(file_name);
Document doc = builder.parse(ip_src);
System.out.println(file_name + " is well-formed!");
}
catch (Exception e)
{
System.out.println(file_name + " isn't well-formed!");
System.exit(1);
}
}
else
{
System.out.print("File not found!");
}
}
catch(IOException ex)
{
ex.printStackTrace();
}
}
}
sax.xml:
<?xml version="1.0"?>
<student>
<name>SHARAN</name>
sax.xml:
<?xml version="1.0"?>
<student>
<name>SHARAN</name>
</student>
RESULT:
Thus the program for DOM is successfully executed and output is verified.
EX.NO: 8(b) PROGRAM USING SAX WITH XML
DATE:
AIM:
To write a program using SAX along with XML file.
ALGORITHM:
Step 1: Start the program
Step 2: Keep the xml and java file in the same folder.
Step 3: Import the required packages initially.
Step 4: Use Buffer Reader to read the contents from the command prompt.
Step 5: Get the name of the xml file from the user to execute.
Step 6: Using XML Reader Factory obtain the parser.
Step 7: If the document is correctly parsed then print document is well formed else print document is not well formed.
Step 8: Stop the program.
Coding:
import java.io.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
public class Parsing_SAXDemo
{
public static void main(String[] args) throws IOException
{
try
{
System.out.print("Enter the name of XML document ");
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String file_name = input.readLine();
File fp = new File(file_name);
if (fp.exists())
{
try
{
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.parse(file_name);
System.out.println(file_name + " is well-formed.");
}
catch (Exception e)
{
System.out.println(file_name + " is not well-formed.");
System.exit(1);
}
}
else
{
System.out.println("File is not present: " + file_name);
}
}
catch (IOException ex){ex.printStackTrace();}
}
}
two.xml
<?xml version="1.0"?>
<student>
<name>SURESH</name>
OUTPUT:
two.xml
<?xml version="1.0"?>
<student>
<name>SURESH</name>
RESULT:
Thus the program for SAX is successfully executed and output is verified.
EX.NO: 9 PROGRAM USING AJAX
DATE:
Aim:
To write programs to search and display chemistry element’s definition detail using JSP.
Algorithm:
Step 1: Start the Program
Step 2: Enter the chemistry element in index.html
Step 3: Read the element data by request.getParameter() on chems.jsp.
Step 4: Check given element in element list.
Step 5: Display the definition of given element.
Step 6: Stop the Program
PROGRAM:
PROGRAM:
Chems.html
<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
var data = (t1.value);
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","chems.jsp?t1="+data,true);
xmlhttp.send();
}
</script>
</head>
<body>
<table>
<tr><td witdh=150> Enter the Chem Name : </td>
<td> <Input type=text name=t1 ></td>
</tr>
<tr><td witdh=150> Chem Name : </td><td> <div id="myDiv"></div></td>
</tr>
<tr><td> <button type="button" onClick="loadXMLDoc()">Change Content</button></td>
</tr>
</table>
</body>
</html>
chems.jsp
<%
String d=request.getParameter("t1");
String[]name;
int i=0,n=0;
name=new String[10];
name[0]="atomic number";
name[1]="catalyst";
name[2]="acid";
name[3]="base";
name[4]="bond energy";
name[5]="chain reactons";
name[6]="covalent bonds";
name[7]="element";
name[8]="enzyme";
name[9]="kinetics";
String[] defn;
defn=new String[10];
defn[0]="It is defined as the number of protons or electrons.";
defn[1]="a catalyst is a substance which fastens a reaction without themselves undergoing any change.";
defn[2]="An agent able to produce positively charged hydrogen ions.";
defn[3]="A base is a substance that can combine with a proton.";
defn[4]="The energy required to break a particular bond by hompolytic process.";
defn[5]="chain reaction:reactions which proceed by means of a set of repeating cyclic steps.";
defn[6]="Linkage of two atoms by the sharing of two electrons.";
defn[7]="a substance which cannot be further subdivided by chemical methods.";
defn[8]="a naturally occuringb substance able to catalyse a chemical reaction.";
defn[9]="The study of rate of reactions.";
for(i=0;i<9;i++)
{
if(d.equals(name[i]))
n=i;
}
out.println(defn[n]);
Thus the program was successfully executed and the output was verified.
EX.NO: 10 web service-DATABASE CONNECTIVITY
DATE:
AIM:
To implement a program to run the web service.
ALGORITHM:
Step 1: Start the Program
Step 2: Create a new service web application as server in net beans
Step 3: In the server side web application, save the NewWebService program in java extension.
Step 4: In the web service side name the pack as pack1
Step 5: Clean and build the server side and then text the web service
Step 6: Create the client side as web application client and save the programs in jsp and html extension
Step 7: Clean and build the server side and then text the web service client
Step 8: Stop the Program
CODING:
NewWebService.java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pack1;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import java.sql.*;
/**
*
* @author SREC
*/
@WebService()
public class NewWebService {
@WebMethod (operationName="get")
public String[] get(@WebParam(name="from")String from,@WebParam (name="to")String to)
{
String hello[]=new String[6];
int i=0;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String filename = "d:/data1.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database+= filename.trim() + ";DriverID=22;READONLY=true}";
Connection con = DriverManager.getConnection( database ,"","");
Statement s = con.createStatement();
s.execute("select * from details ");
ResultSet rs = s.getResultSet();
if (rs != null)
while ( rs.next() )
{
hello[i]= rs.getString("name");
i++;
hello[i]= rs.getString("date");
i++;
}
}
catch (Exception e) {
System.out.println("Error: " + e);
}
return hello;
}
}
Index.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<form name="air" action="action.jsp" method="post">
From<input type="text" name="from" id="from"><br/>
To<input type="text" name="to" id="to"><br/>
<input type="submit" value="GetDtails">
</form>
</body>
</html>
Action.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<%
String from1=request.getParameter("from");
String to1=request.getParameter("to");
%>
<%-- start web service invocation --%><hr/>
<%
try {
pack1.NewWebServiceService service = new pack1.NewWebServiceService();
pack1.NewWebService port = service.getNewWebServicePort();
// TODO initialize WS operation arguments here
java.lang.String from = from1;
java.lang.String to = to1;
// TODO process result here
java.util.List<java.lang.String> result = port.get(from, to);
out.println("Result = "+result);
} catch (Exception ex) {
// TODO handle custom exceptions here
}
%>
<%-- end web service invocation --%><hr/>
</body>
</html>
RESULT:
Thus the program was successfully executed and the output was verified.
==================*******************==================================
==================*******************==================================
No comments:
Post a Comment
comments ...pls