63
IMPLEMENTATION OF IMAGE WITH HOT SPOTS CODING: home.html <html> <head> <title>image</title> </head> <body> <p><b><i>BIRD</i></b></p> <img src ="E:\Saran\ex1\bird.jpg" width="500"height="500" usemap="#bird"> <map id="bird" name="bird"> <area shape="rect" coords="1,1,328,659" alt="Bird right" href="E:\Saran\ ex1\left.html"> <area shape="rect"coords="335,1,659,659" alt="Bird left" href="E:\Saran\ ex1\right.html"> </map> </body> <html> left.html <html> <head> <title>left</title> </head> <body><font face="monotypr corsiva" size=6> <i><b>LEFT SIDE</i></b> THIS shows the bird alone</br></font> <img src ="E:\Saran\ex1\bird left.jpg" width="250"height="250"/> </body> </html> right.html 1

Internet Programming Lab Manual

Embed Size (px)

Citation preview

Page 1: Internet Programming Lab Manual

IMPLEMENTATION OF IMAGE WITH HOT SPOTS

CODING:

home.html<html>

<head>

<title>image</title>

</head>

<body>

<p><b><i>BIRD</i></b></p>

<img src ="E:\Saran\ex1\bird.jpg" width="500"height="500" usemap="#bird">

<map id="bird" name="bird">

<area shape="rect" coords="1,1,328,659" alt="Bird right" href="E:\Saran\ex1\left.html">

<area shape="rect"coords="335,1,659,659" alt="Bird left" href="E:\Saran\ex1\right.html">

</map>

</body>

<html>

left.html<html>

<head>

<title>left</title>

</head>

<body><font face="monotypr corsiva" size=6>

<i><b>LEFT SIDE</i></b>

THIS shows the bird alone</br></font>

<img src ="E:\Saran\ex1\bird left.jpg" width="250"height="250"/>

</body>

</html>

right.html<html>

<head>

<title>right</title>

</head>

<body><font face="monotypr corsiva" size=6>

<i><b>RIGHT SIDE</i></b>

THIS shows the flower alone</br></font>

<img src ="E:\Saran\ex1\bird right.jpg" width="100"height="150"/>

</body> </html>

1

Page 2: Internet Programming Lab Manual

OUTPUT:

Home page

2

Page 3: Internet Programming Lab Manual

When left side of home page is clicked

3

Page 4: Internet Programming Lab Manual

When right side of home page is clicked

4

Page 5: Internet Programming Lab Manual

IMPLEMENTATION OF STYLE SHEETS

(INTERNAL STYLE SHEET)

CODING:

home.html<html>

<head>

<title>css image</title>

</head>

<body bgcolor="c0c0c0">

<font face="monotype corsiva" size=6> <p> STYLE SHEETS</p>

<a href="e:\Saran\ex2\internal.html">INTERNAL SYTLE</a></br>

<a href="e:\Saran\ex2\external.html">EXTERNAL STYLE</a>

</map>

</body>

<html>

internal.html<html>

<head>

<title>internal</title>

<style type="text/css">

h1

{font-family:Monotype Corsiva;

size:5;

color:pink;

}

h2

{font-family:Monotype Corsiva;

size:5;

color:green;

}

body

{

background-image:url('e:\Saran\ex2\bird left.jpg');

background-repeat:no-repeat;

}

</style>

</head>

<body><h1>

5

Page 6: Internet Programming Lab Manual

Internal style applied</h1>

<h2>

THIS shows the bird alone</br></h2>

<img src ="e:\Saran\ex2\bird left.jpg" width="200"height="250"/>

</body>

</html>

external.html<html>

<head>

<title>External</title>

<link rel="stylesheet"type="text/css" href="e:\Saran\ex2\style.css">

</head>

<body class="body1"><h1>

External style applied</h1>

<h2 class="green">

THIS shows the FLOWER alone</br></h2>

<h2 class="yellow">

THIS shows the FLOWER alone</br></h2>

<img src ="e:\Saran\ex2\bird right.jpg" width="100"height="150"/>

</body> </html>

style.css.body1

{

background-image:url(bgimg.jpg);

background-repeat:no-repeat;

}

h1

{font-family:Monotype Corsiva;

size:5;

color:pink;

}

h2.green

{font-family:Monotype Corsiva;

size:5;

color:green;

}

h2.yellow

{font-family:Monotype Corsiva;

size:5;

color:yellow;

6

Page 7: Internet Programming Lab Manual

}

OUTPUT:Home page

When internal style hyperlink is clicked

7

Page 8: Internet Programming Lab Manual

When external style hyperlink is clicked

8

Page 9: Internet Programming Lab Manual

FORM VALIDATION

CODING:

//Form Validation

home.html<html>

<head>

<script type="text/javascript">

function val_name()

{

var name_str=document.form1.name;

if((name_str.value==null) || (name_str.value==""))

{

alert("Enter the name");

return false;

}

if(name_str.value.length>6)

{

alert("Enter within 6 chars");

document.form1.name.value="";

}

}

function val_age()

{

var age_str=document.form1.age;

if((age_str.value==null) || (age_str.value==""))

{

alert("Enter the age");

return false;

}

if((age_str.value<"5")&&(age_str.value>"21"))

{

alert(" Invalid age")

return false;

}

}

function val_mobile()

{

var mobile_str=document.form1.mobile;

9

Page 10: Internet Programming Lab Manual

if((mobile_str.value==null) || (mobile_str.value==""))

{

alert("Enter the mobile number");

return false;

}

if((mobile_str.value.length<"10")||(mobile_str.value.length>"10"))

{

alert("Invalid length of mobie number");

document.form1.mobile.value="";

}

if(isNaN(mobile_str.value))

{

alert("Invalid mobie number");

document.form1.mobile.value="";

} }

function val_email()

{

var email_str=document.form1.email.value;

if((email_str.indexOf("@",1))<0)

{

alert("Invalid Email Id ");

document.form1.email.value="";

} }

function val_email()

{

var email_str=document.form1.email;

var email=email_str.value;

var len=email_str.length;

var index_at=email.indexOf("@");

var index_dot=email.indexOf(".");

if(email.indexOf("@")==-1)

{

alert("Atleast one @ should be there in a email id");

return false;

}

if((email.indexOf(".")==-1)||(email.indexOf(".")==0)||(email.indexOf(".")==1))

{

alert("Atleast one . should be there in a email id or invalid position of . ");

return false;

}

10

Page 11: Internet Programming Lab Manual

if(email.indexOf(" ")!=-1)

{

alert("Space should not be there in a email id");

return false;

} }

</script>

</head>

<body bgcolor="pink">

<form name="form1" action="success.html">

<center>

<b>APPLICATION FORM</b> <br/><br/><br/><br/><br/><br/>

NAME:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<input type="text" name="name" onblur=val_name() > <br/> <br/>

AGE:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;

<input type="text" name="age" onblur=val_age()> <br/> <br/>

MOBILE NO:

&nbsp;&nbsp;

<input type="text" name="mobile" onblur=val_mobile()> <br/> <br/>

EMAIL ID:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<input type="text" name="email" onblur=val_email()> <br/> <br/>

<input type="submit" value=SUBMIT>

</center>

</form>

</body>

</html>

success.html<html> <body>

<center>

<b>REGISTRATION IS SUCCESSFULL!!!!!</b>

</center>

</body>

</html>

11

Page 12: Internet Programming Lab Manual

OUTPUT:

12

Page 13: Internet Programming Lab Manual

13

Page 14: Internet Programming Lab Manual

14

Page 15: Internet Programming Lab Manual

15

Page 16: Internet Programming Lab Manual

IMPLEMENTATION OF APPLET USING JAVA

CODING:

// CREATING APPLET USING JAVA

pg4.javaimport java.awt.*;

import java.awt.event.*;

import java.applet.*;

public class pg4 extends Applet implements ItemListener

{

int currcolor=5;

int flag=1;

String text="Click any of the button";

Button button[]=new Button[5];

String colors[]={"red","blue","green","yellow","magenta"};

Image img;

CheckboxGroup cbg=new CheckboxGroup();

Checkbox box1=new Checkbox("BackgroundColor",cbg,true);

Checkbox box2=new Checkbox("TextColor",cbg,false);

Checkbox box3=new Checkbox("Load my image",cbg,false);

public void init()

{

for(int i=0;i<5;i++)

{

button[i]=new Button("");

add(button[i]);

}

button[0].setBackground(Color.red);

button[1].setBackground(Color.blue);

button[2].setBackground(Color.green);

button[3].setBackground(Color.yellow);

button[4].setBackground(Color.magenta);

add(box1);

add(box2);

add(box3);

box1.addItemListener(this);

box2.addItemListener(this);

box3.addItemListener(this);

16

Page 17: Internet Programming Lab Manual

}

public void itemStateChanged(ItemEvent e)

{

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(),"image.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);

17

Page 18: Internet Programming Lab Manual

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;

}

}

else

if(flag==3)

{

g.drawImage(img,20,90,this);

}

}

18

Page 19: Internet Programming Lab Manual

public boolean action(Event e,Object o)

{

for(int i=0;i<5;i++)

{

if(e.target==button[i])

{

currcolor=i;

text="you hav chose " +colors[i];

repaint();

return true;

} }

return false;

}

}

pg4.html

<html>

<center>

<applet code="pg4.class" height="500" width="800">

</applet>

</center>

</html>

image.jpg

19

Page 20: Internet Programming Lab Manual

OUTPUT:

20

Page 21: Internet Programming Lab Manual

21

Page 22: Internet Programming Lab Manual

INVOKING SERVLETS USING HTML

CODING:

//Invoking servlet from a HTML form

ServletDemo.javapackage org;

import java.io.*;

import java.util.*;

import javax.servlet.*;

public class ServletDemo extends GenericServlet {

public void service(ServletRequest request, ServletResponse response)

throws ServletException, IOException {

PrintWriter out = response.getWriter();

Enumeration en = request.getParameterNames();

while (en.hasMoreElements()) {

String name_received = (String) en.nextElement();

out.print(name_received + "=");

String value_received = request.getParameter(name_received);

out.println(value_received);

out.println("");

}

out.close();

}

}

index.html<html>

<head>

<title>Student Information form </title>

</head>

<body>

<center>

<form name="form1" action="/ServletDemo/action/register.action" method="POST">

<h3>Enter student information in following fields</h3>

<table>

<tr>

<td><b>Rollno</b></td>

<td><input type="text" name="Roll number" size="25" value=""></td>

</tr>

<tr>

22

Page 23: Internet Programming Lab Manual

<td><b>Student name</b></td>

<td><input type="text" name="Student Name" size="25" value=""></td>

</tr>

<tr>

<td><b>Student Address</b></td>

<td><input type="text" name="Student Address" size="25" value=""></td>

</tr>

<tr>

<td><b>Phone</b></td>

<td><input type="text" name="Phone" size="25" value=""></td>

</tr>

<tr>

<td><b>Total Marks</b></td>

<td><input type="text" name="Total Marks" size="25" value=""></td>

</tr>

</table>

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

</form>

</center>

</body>

</html>

web.xml<servlet>

<servlet-name>controller</servlet-name>

<servlet-class>org.ServletDemo</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>controller</servlet-name>

<url-pattern>/action/*</url-pattern>

</servlet-mapping>

23

Page 24: Internet Programming Lab Manual

OUTPUT:

24

Page 25: Internet Programming Lab Manual

25

Page 26: Internet Programming Lab Manual

THREE TIER APPLICATION

CODING:

//create a class called UserController and put the following contentpackage org;

import java.io.IOException;

import javax.servlet.RequestDispatcher;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpServlet;

public class UserController extends HttpServlet {

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

System.out.println("inside service method");

String name = request.getParameter("studentName");

String rollno = request.getParameter("rollno");

UserDataManager dataManager = new UserDataManager();

try {

dataManager.register(name, rollno);

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

RequestDispatcher page = request.getRequestDispatcher("/result.jsp");

page.forward(request, response);

} }

//create a class called UserDataManager and put the following contentpackage org;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.util.Properties;

import org.hsqldb.jdbc.JDBCDriver;

public class UserDataManager {

//driver for 2.2.8

private String driverClassName = "org.hsqldb.jdbc.JDBCDriver";

private String url = "jdbc:hsqldb:hsql://localhost";

{

try {

Connection connection = getConnection();

26

Page 27: Internet Programming Lab Manual

connection.prepareStatement("CREATE TABLE STUDENT(ROLLNO INTEGER, NAME

VARCHAR(200), DOB DATE)").execute();

}catch(Exception exception) {

if(exception.getMessage().indexOf("object name already exists: STUDENT")==-1){

exception.printStackTrace();

}} }

public Connection getConnection() throws Exception {

Class clazz = Class.forName(driverClassName);

JDBCDriver driver = (JDBCDriver) clazz.newInstance();

Properties properties = new Properties();

properties.setProperty("user", "SA");

properties.setProperty("password", "");

Connection connection = driver.connect(url, properties);

return connection;

}

public void register(String name,String rollno)

throws Exception {

System.out.println("inside register method");

String sql = "insert into student values (?,?,?)";

Connection connection = getConnection();

PreparedStatement pStmt = connection.prepareStatement(sql);

pStmt.setInt(1, Integer.parseInt(rollno));

pStmt.setString(2, name);

pStmt.setDate(3,new java.sql.Date(System.currentTimeMillis()));

pStmt.executeUpdate();

pStmt.close();

connection.commit();

connection.close();

}}

//create a index.jsp in webcontent<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

<!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=ISO-8859-1">

<title>Insert title here</title>

</head>

<body>

27

Page 28: Internet Programming Lab Manual

<form action="/3TierWebProject/action/register.action" method="POST">

Enter the student name:

<input name="studentName"/><br/>

Enter the rollno:

<input name="rollno"/><br/>

<input type="button" value="register" onclick="form.submit()"/>

</form>

</body>

</html>

//create a result.jsp and put the following content<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

<!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=ISO-8859-1">

<title>Insert title here</title>

</head>

<body>

user details saved successfully.

</body>

</html>

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

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app id="WebApp_ID">

<display-name>3TierWebProject</display-name>

<servlet>

<servlet-name>controller</servlet-name>

<servlet-class>org.UserController</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>controller</servlet-name>

<url-pattern>/action/*</url-pattern>

</servlet-mapping>

</web-app>

28

Page 29: Internet Programming Lab Manual

OUTPUT:

run runManager.bat

29

Page 30: Internet Programming Lab Manual

30

Page 31: Internet Programming Lab Manual

31

Page 32: Internet Programming Lab Manual

32

Page 33: Internet Programming Lab Manual

IMPLEMENTING XML SCHEMA

CODING:

//Implementation of XML Schema

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

<dept xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:noNameSpaceSchemaLocation="xmlschema.xsd">

<csedept xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:noNameSpaceSchemaLocation="xmlschema.xsd">

<section>cse-a</section>

<year>3</year>

<staff>xxx</staff>

<phno>123456</phno>

<date>19.11.1991</date>

<result>true</result>

</csedept>

<ecedept xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:noNameSpaceSchemaLocation="dept.xsd">

<section>ece-a</section>

<year>1</year>

<staff>xxy</staff>

<phno>654321</phno>

<date>19.11.1990</date>

<result>true</result>

</ecedept>

<aerodept xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:noNameSpaceSchemaLocation="dept.xsd">

<section>aero-a</section>

<year>2</year>

<staff>xyy</staff>

<phno>456789</phno>

<date>19.11.1992</date>

<result>false</result>

</aerodept>

<eeedept xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:noNameSpaceSchemaLocation="dept.xsd">

<section>eee-a</section>

<year>4</year>

<staff>yyy</staff>

33

Page 34: Internet Programming Lab Manual

<phno>789456</phno>

<date>19.11.1994</date>

<result>true</result>

</eeedept>

<mechdept xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:noNameSpaceSchemaLocation="dept.xsd">

<section>mech-a</section>

<year>3</year>

<staff>zzz</staff>

<phno>147852</phno>

<date>19.11.1991</date>

<result>true</result>

</mechdept>

</dept>

xmlschema.xsd<?xml version="1.0"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="dept">

<xs:complexType>

<xs:sequence>

<xs:element name="csedept">

<xs:complexType>

<xs:sequence>

<xs:element name="section"type="xs:string"/>

<xs:element name="year"type="xs:integer"/>

<xs:element name="staff"type="xs:string"/>

<xs:element name="phno"type="xs:integer"/>

<xs:element name="date"type="xs:date"/>

<xs:element name="result"type="xs:boolean"/>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="ecedept">

<xs:complexType>

<xs:sequence>

<xs:element name="section"type="xs:string"/>

<xs:element name="year"type="xs:integer"/>

<xs:element name="staff"type="xs:string"/>

<xs:element name="phno"type="xs:integer"/>

34

Page 35: Internet Programming Lab Manual

<xs:element name="date"type="xs:date"/>

<xs:element name="result"type="xs:boolean"/>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="aerodept">

<xs:complexType>

<xs:sequence>

<xs:element name="section"type="xs:string"/>

<xs:element name="year"type="xs:integer"/>

<xs:element name="staff"type="xs:string"/>

<xs:element name="phno"type="xs:integer"/>

<xs:element name="date"type="xs:date"/>

<xs:element name="result"type="xs:boolean"/>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="eeedept">

<xs:complexType>

<xs:sequence>

<xs:element name="section"type="xs:string"/>

<xs:element name="year"type="xs:integer"/>

<xs:element name="staff"type="xs:string"/>

<xs:element name="phno"type="xs:integer"/>

<xs:element name="date"type="xs:date"/>

<xs:element name="result"type="xs:boolean"/>

</xs:sequence>

</xs:complexType>

</xs:element>

<xs:element name="mechdept">

<xs:complexType>

<xs:sequence>

<xs:element name="section"type="xs:string"/>

<xs:element name="year"type="xs:integer"/>

<xs:element name="staff"type="xs:string"/>

<xs:element name="phno"type="xs:integer"/>

<xs:element name="date"type="xs:date"/>

<xs:element name="result"type="xs:boolean"/>

</xs:sequence>

</xs:complexType>

35

Page 36: Internet Programming Lab Manual

</xs:element>

<xs:element name="civildept">

<xs:complexType>

<xs:sequence>

<xs:element name="section"type="xs:string"/>

<xs:element name="year"type="xs:integer"/>

<xs:element name="staff"type="xs:string"/>

<xs:element name="phno"type="xs:integer"/>

<xs:element name="date"type="xs:date"/>

<xs:element name="result"type="xs:boolean"/>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>0

</xs:element>

</xs:schema>

36

Page 37: Internet Programming Lab Manual

OUTPUT:

37

Page 38: Internet Programming Lab Manual

IMPLEMENTATION OF XSLT

CODING:

//Transformation of XML document (XSLT)

student.xml:<?xml version="1.0"?>

<?xml-stylesheet type="text/xsl" href="student.xsl"?>

<student>

<per_info>

<name>AAA</name>

<address>erode</address>

<mobile>9568321445</mobile>

</per_info>

<per_info>

<name>BBB</name>

<address>kallakurichi</address>

<mobile>9568355645</mobile>

</per_info>

<per_info>

<name>CCC</name>

<address>salem</address>

<mobile>9452136895</mobile>

</per_info>

</student>

student.xslt<?xml version="1.0"?>

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

<html> <body>

<center>

<h2>STUDENT DETAILS</h2>

<table border="1">

<tr bgcolor="pink">

<th>NAME</th>

<th>ADDRESS</th>

<th>MOB-NO</th>

</tr>

<xsl:for-each select="student/per_info">

38

Page 39: Internet Programming Lab Manual

<tr bgcolor="gray">

<td><xsl:value-of select="name"/></td>

<td><xsl:value-of select="address"/></td>

<td><xsl:value-of select="mobile"/></td>

</tr>

</xsl:for-each>

</table>

</center>

</body> </html>

</xsl:template>

</xsl:stylesheet>

39

Page 40: Internet Programming Lab Manual

OUTPUT:

40

Page 41: Internet Programming Lab Manual

IMPLEMENTATION OF AJAX CLIENT SIDE

CODING:

//Implementation of AJAX (Asynchronous Java Script)

ajax.html<html>

<head>

<script type="text/javascript">

function myfun()

{

if(window.XMLHttpRequest)

{

req=new XMLHttpRequest();

}

else

{

req=new ActiveXObject("Microsoft.req");

}

req.onreadystatechange=function()

{

if(req.readyState==4 && req.status==200)

{

document.getElementById("myID").innerHTML=req.respose.Text;

}

}

req.open("GET",newdata.txt",true);

req.send();

}

</script>

</head>

<body>

<div id="myID">This text can be changed</div>

<button type="button" onclick="myfun()"> Change </button>

</body>

</html>

41

Page 42: Internet Programming Lab Manual

OUTPUT:

42

Page 43: Internet Programming Lab Manual

IMPLEMENTATION OF AJAX SERVER SIDE

CODING:

//Implementation of AJAX (Asynchronous Java Script) – Server Side

index.jsp<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

<!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=ISO-8859-1">

<title>Insert title here</title>

<script>

var connection = getConnection();

functiongetConnection() {

if (window.XMLHttpRequest) {

//code for IE7+, Firefox, Chrome, Opera, Safari

return new XMLHttpRequest();

} else {

// code for IE6, IE5

return new ActiveXObject("Microsoft.XMLHTTP");

}

}

functionretrieveContent() {

connection.open('post','message.txt');

connection.onreadystatechange=pasteContent;

connection.send();

}

functionpasteContent() {

varcontentDiv = document.getElementById('contentDiv');

contentDiv.innerHTML = connection.responseText;

}

</script>

</head>

<body>

Welcome to Ajax program!!

<div id="contentDiv">this content will be replaced with ajax content, click the retrive button</div>

43

Page 44: Internet Programming Lab Manual

<input type="button" value="retrieve"

onclick="retrieveContent()"/>

</body>

</html>

message.txtWelcome to Ajax program!!

Welcome to IP Lab

44

Page 45: Internet Programming Lab Manual

OUTPUT:

45

Page 46: Internet Programming Lab Manual

AIRLINE RESERVATION SYSTEM USING WEB SERVICES

CODING:package airinfo;

import java.rmi.RemoteException;

public interface MyInterface extends java.rmi.Remote

{

public String getInfo(String src,String dest)throws java.rmi.RemoteException;

}

package airinfo;

import java.sql.*;

public class TestDB implements MyInterface

{

public String getInfo(String src,String dest)

{

String str="";

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection con=DriverManager.getConnection("jdbc:odbc:Airways","","");

Statement s=con.createStatement();

if(src.equals("Mumbai"))

{

if(dest.equals("Pune"))

s.executeQuery("SELECT * FROM Airways_table WHERE Start_from='Mumbai'

AND Dest='Pune'");

else if(dest.equals("Chennai"))

s.executeQuery("SELECT * FROM Airways_table WHERE Start_from='Mumbai'

AND Dest='Chennai'");

}

else if(src.equals("Pune"))

{

if(dest.equals("Mumbai"))

s.executeQuery("SELECT * FROM Airways_table WHERE Start_from='Pune' AND

Dest='Mumbai'");

else if(dest.equals("Chennai"))

s.executeQuery("SELECT * FROM Airways_table WHERE Start_from='Pune' AND

Dest='Chennai'");

}

else if(src.equals("Chennai"))

46

Page 47: Internet Programming Lab Manual

{

if(dest.equals("Pune"))

s.executeQuery("SELECT * FROM Airways_table WHERE Start_from='Chennai'

AND Dest='Pune'");

else if(dest.equals("Mumbai"))

s.executeQuery("SELECT * FROM Airways_table WHERE Start_from='Chennai'

AND Dest='Mumbai'");

}

ResultSet rs=s.getResultSet();

str+="<table border=1>";

while(rs.next())

{

str+="<tr><b>";

str+="<td>";

str+=rs.getString("name");

str+="</td>";

str+="<td>";

str+=rs.getString("Time");

str+="</td>";

str+="</tr></b>";

}

str+="</table>";

}catch(ClassNotFoundException ex)

{

System.out.println(ex);

}

catch(SQLException ex)

{

System.out.println(ex);

}

return str;

}}

// This class was generated by the JAXRPC SI, do not edit.

// Contents subject to change without notice.

// JAX-RPC Standard Implementation (1.1.3, build R1)

// Generated source version: 1.1.3

package myairreservationclient;

import com.sun.xml.rpc.client.BasicService;

import com.sun.xml.rpc.encoding.*;

import com.sun.xml.rpc.encoding.simpletype.*;

47

Page 48: Internet Programming Lab Manual

import com.sun.xml.rpc.encoding.soap.*;

import com.sun.xml.rpc.encoding.literal.*;

import com.sun.xml.rpc.soap.SOAPVersion;

import com.sun.xml.rpc.wsdl.document.schema.SchemaConstants;

import javax.xml.rpc.*;

import javax.xml.rpc.encoding.*;

import javax.xml.namespace.QName;

public class AirLineReservation_SerializerRegistry implements SerializerConstants {

public AirLineReservation_SerializerRegistry()

{

}

public TypeMappingRegistry getRegistry()

{

TypeMappingRegistry registry = BasicService.createStandardTypeMappingRegistry();

TypeMapping mapping12 = registry.getTypeMapping(SOAP12Constants.NS_SOAP_ENCODING);

TypeMapping mapping = registry.getTypeMapping(SOAPConstants.NS_SOAP_ENCODING);

TypeMapping mapping2 = registry.getTypeMapping("");

{

QName type = new QName("http://tempuri.org/wsdl", "getInfo");

CombinedSerializer serializer = new

myairreservationclient.MyInterface_getInfo_RequestStruct_SOAPSerializer(type,

DONT_ENCODE_TYPE, NULLABLE, SOAPConstants.NS_SOAP_ENCODING);

serializer = new ReferenceableSerializerImpl(DONT_SERIALIZE_AS_REF, serializer,

SOAPVersion.SOAP_11);

registerSerializer(mapping,myairreservationclient.MyInterface_getInfo_RequestStruct.class, type,

serializer);

}{

QName type = new QName("http://tempuri.org/wsdl", "getInfoResponse");

CombinedSerializer serializer = new

myairreservationclient.MyInterface_getInfo_ResponseStruct_SOAPSerializer(type,

DONT_ENCODE_TYPE, NULLABLE, SOAPConstants.NS_SOAP_ENCODING);

serializer = new ReferenceableSerializerImpl(DONT_SERIALIZE_AS_REF, serializer,

SOAPVersion.SOAP_11);

registerSerializer(mapping,myairreservationclient.MyInterface_getInfo_ResponseStruct.class, type,

serializer);

}

return registry;

}

private static void registerSerializer(TypeMapping mapping, java.lang.Class javaType,

javax.xml.namespace.QName xmlType,

48

Page 49: Internet Programming Lab Manual

Serializer ser) {

mapping.register(javaType, xmlType, new SingletonSerializerFactory(ser),

new SingletonDeserializerFactory((Deserializer)ser));

}

}

// This class was generated by the JAXRPC SI, do not edit.

// Contents subject to change without notice.

// JAX-RPC Standard Implementation (1.1.3, build R1)

// Generated source version: 1.1.3

package myairreservationclient;

public class MyInterface_getInfo_ResponseStruct {

protected java.lang.String result;

public MyInterface_getInfo_ResponseStruct() {

}

public MyInterface_getInfo_ResponseStruct(java.lang.String result) {

this.result = result;

}

public java.lang.String getResult() {

return result;

}

public void setResult(java.lang.String result) {

this.result = result;

}

}

// This class was generated by the JAXRPC SI, do not edit.

// Contents subject to change without notice.

// JAX-RPC Standard Implementation (1.1.3, build R1)

// Generated source version: 1.1.3

package myairreservationclient;

import com.sun.xml.rpc.encoding.*;

import com.sun.xml.rpc.util.exception.LocalizableExceptionAdapter;

public class MyInterface_getInfo_RequestStruct_SOAPBuilder implements SOAPInstanceBuilder {

private myairreservationclient.MyInterface_getInfo_RequestStruct _instance;

private java.lang.String string_1;

private java.lang.String string_2;

private static final int mySTRING_1_INDEX = 0;

private static final int mySTRING_2_INDEX = 1;

public MyInterface_getInfo_RequestStruct_SOAPBuilder() {

}

public void setString_1(java.lang.String string_1) {

49

Page 50: Internet Programming Lab Manual

this.string_1 = string_1;

}

public void setString_2(java.lang.String string_2) {

this.string_2 = string_2;

}

public int memberGateType(int memberIndex) {

switch (memberIndex) {

case mySTRING_1_INDEX:

return GATES_INITIALIZATION | REQUIRES_CREATION;

case mySTRING_2_INDEX:

return GATES_INITIALIZATION | REQUIRES_CREATION;

default:

throw new IllegalArgumentException();

}

}

public void construct() {

}

public void setMember(int index, java.lang.Object memberValue) {

try {

switch(index) {

case mySTRING_1_INDEX:

_instance.setString_1((java.lang.String)memberValue);

break;

case mySTRING_2_INDEX:

_instance.setString_2((java.lang.String)memberValue);

break;

default:

throw new java.lang.IllegalArgumentException();

}

}

catch (java.lang.RuntimeException e) {

throw e;

}

catch (java.lang.Exception e) {

throw new DeserializationException(new LocalizableExceptionAdapter(e));

}

}

public void initialize() {

}

public void setInstance(java.lang.Object instance) {

50

Page 51: Internet Programming Lab Manual

_instance = (myairreservationclient.MyInterface_getInfo_RequestStruct)instance;

}

public java.lang.Object getInstance() {

return _instance;

}

}

// This class was generated by the JAXRPC SI, do not edit.

// Contents subject to change without notice.

// JAX-RPC Standard Implementation (1.1.3, build R1)

// Generated source version: 1.1.3

package myairreservationclient;

public interface MyInterface extends java.rmi.Remote {

public java.lang.String getInfo(java.lang.String string_1, java.lang.String string_2) throws

java.rmi.RemoteException;

}

// This class was generated by the JAXRPC SI, do not edit.

// Contents subject to change without notice.

// JAX-RPC Standard Implementation (1.1.3, build R1)

// Generated source version: 1.1.3

package myairreservationclient;

import com.sun.xml.rpc.encoding.*;

import com.sun.xml.rpc.client.ServiceExceptionImpl;

import com.sun.xml.rpc.util.exception.*;

import com.sun.xml.rpc.soap.SOAPVersion;

import com.sun.xml.rpc.client.HandlerChainImpl;

import javax.xml.rpc.*;

import javax.xml.rpc.encoding.*;

import javax.xml.rpc.handler.HandlerChain;

import javax.xml.rpc.handler.HandlerInfo;

import javax.xml.namespace.QName;

public class AirLineReservation_Impl extends com.sun.xml.rpc.client.BasicService implements

AirLineReservation {

private static final QName serviceName = new QName("http://tempuri.org/wsdl", "AirLineReservation");

private static final QName ns1_MyInterfacePort_QNAME = new QName("http://tempuri.org/wsdl",

"MyInterfacePort");

private static final Class myInterface_PortClass = myairreservationclient.MyInterface.class;

public AirLineReservation_Impl() {

super(serviceName, new QName[] {

ns1_MyInterfacePort_QNAME

},

51

Page 52: Internet Programming Lab Manual

new myairreservationclient.AirLineReservation_SerializerRegistry().getRegistry());

}

public java.rmi.Remote getPort(javax.xml.namespace.QName portName, java.lang.Class

serviceDefInterface) throws javax.xml.rpc.ServiceException {

try {

if (portName.equals(ns1_MyInterfacePort_QNAME) &&

serviceDefInterface.equals(myInterface_PortClass)) {

return getMyInterfacePort();

}

}

catch (Exception e) {

throw new ServiceExceptionImpl(new LocalizableExceptionAdapter(e));

} return super.getPort(portName, serviceDefInterface);

}

public java.rmi.Remote getPort(java.lang.Class serviceDefInterface) throws

javax.xml.rpc.ServiceException {

try {

if (serviceDefInterface.equals(myInterface_PortClass)) {

return getMyInterfacePort();

} } catch (Exception e) {

throw new ServiceExceptionImpl(new LocalizableExceptionAdapter(e));

}

return super.getPort(serviceDefInterface);

}

public myairreservationclient.MyInterface getMyInterfacePort() {

java.lang.String[] roles = new java.lang.String[] {};

HandlerChainImpl handlerChain = new

HandlerChainImpl(getHandlerRegistry().getHandlerChain(ns1_MyInterfacePort_QNAME));

handlerChain.setRoles(roles);

myairreservationclient.MyInterface_Stub stub = new

myairreservationclient.MyInterface_Stub(handlerChain);

try {

stub._initialize(super.internalTypeRegistry);

} catch (JAXRPCException e) {

throw e;

} catch (Exception e) {

throw new JAXRPCException(e.getMessage(), e);

}

return stub;

52

Page 53: Internet Programming Lab Manual

OUTPUT:

53