ip lab manual

87
EX.NO:1(A) SIMPLE JAVA PROGRAM DATE:11/07/2012 AIM: To write a simple java program to display the required data. ALGORITHM: 1. Create a class named sample. 2. Write the code to display the content “JAVA LAB”. 3. Save the program. 4. Compile and display the result.

Upload: dhasaratha-pandian

Post on 18-Apr-2015

230 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Ip Lab Manual

EX.NO:1(A) SIMPLE JAVA PROGRAM

DATE:11/07/2012

AIM:

To write a simple java program to display the required data.

ALGORITHM:

1. Create a class named sample.2. Write the code to display the content “JAVA LAB”.3. Save the program.4. Compile and display the result.

Page 2: Ip Lab Manual

PROGRAM:

import java.io.*;

class sample

{

public static void main(String s[])

{

System.out.println("JAVA LAB");

}

}

Page 3: Ip Lab Manual

OUTPUT:

Page 4: Ip Lab Manual

RESULT:

Thus a sample java program to display the required data was executed.

Page 5: Ip Lab Manual

EX:NO:1(B) SIMPLE JAVA PROGRAM USING TWO CLASSES

AIM:

To write a simple java program using two classes to find the sum of the given values.

ALGORITHM:

1. Create a class with three integer values.2. Create a method to return the sum of the values.3. Create another class which is the main class.4. Create a class object using this object specify values for the integer.5. Using the object call the method to display the sum of the three integer.6. Compile and display the results.

Page 6: Ip Lab Manual

PROGRAM:

import java.io.*;

class a

{

int l,m,n;

int tot()

{

return l+m+n;}}

class bb

{

public static void main(String args[])

{

int ans;

a obj=new a();

obj.l=60;

obj.m=70;

obj.n=50;

ans=obj.tot();

System.out.println("The total is: "+ans);}

}

Page 7: Ip Lab Manual

OUTPUT:

Page 8: Ip Lab Manual

RESULT:

Thus the sample java program using two classes to find sum of the given values was executed.

Page 9: Ip Lab Manual

EX:NO:1(C) TO DISPLAY DATE AND TIME

AIM:

To write the java program to display current date and time.

ALGORITHM:

1. Create the class with class name.2. To create the package and subpackage from the utility function in java.3. Create the object for a class and call the object to display the date and time.4. Get the input data using the string function.5. Compute and run the program to display the result.

Page 10: Ip Lab Manual

PROGRAM:

import java.util.Calendar;

import java.text.SimpleDateFormat;

public class GetDateNow

{

public static void main(String arg[])

{

Calendar Date=Calendar.getInstance();

SimpleDateFormat formatter=new SimpleDateFormat("yyyy/mm/dd hh:mm:ss");

String DateNow=formatter.format(Date.getTime());

System.out.println("Now the date is:--> "+DateNow);

}

}

Page 11: Ip Lab Manual

OUTPUT:

Page 12: Ip Lab Manual

RESULT:

Thus the Java program to display the current date and time was written and executed.

Page 13: Ip Lab Manual

EX.NO:02 EVENT HANDLING MECHANISM

DATE:12/07/2012

AIM:

To write a java program for the event handling mechanism.

ALGORITHM:

1. Generate a window which can be viewed with an applet viewer.2. Create a subclass ‘test’ inherited from superclass Applet.3. Declare label l1,l2,button b1,textfield tf1,tf2,textarea ta.4. Initialise variable l1,l2,tf1,tf2,ta and b1.5. Create an object bh for class ButtonHandler.6. Using add() method labels,button,textfield and textarea are added to the window.7. The Label of ‘Submit’ button is obtained y calling the getAction command() method on the

ActionEvent object passed to action Performed().8. ActionEvent object is passed as a reference to string ‘s’.9. If ‘submit’ button is pressed contents of tf1 and tf2 are concatenated and are displayed on the

window.

PROGRAM:

Page 14: Ip Lab Manual

import java.awt.*;import java.awt.event.*;import java.applet.*;import java.io.*;public class Event extends Applet{Label l1,l2;Button b1;TextField tf1,tf2;TextArea ta;public void init(){

l1=new Label("Text 1");l2=new Label("Text 2");tf1=new TextField(20); tf2=new TextField(20);b1=new Button("Submit");ta=new TextArea(10,20);ButtonHandler bh=new ButtonHandler();b1.addActionListener(bh);add(l1);add(l2);add(tf1);add(tf2);add(ta);add(b1);}class ButtonHandler implements ActionListener{public void actionPerformed(ActionEvent ae){String s=ae.getActionCommand();if(s.equals("Submit")){ta.setText(tf1.getText()+tf2.getText());}}}}

OUTPUT:

Page 15: Ip Lab Manual
Page 16: Ip Lab Manual

RESULT:

Thus the program for event handling mechanism has been written and executed.

EX.NO:03 FILE HANDLING

Page 17: Ip Lab Manual

DATE:25/07/2012

AIM:

To create a file, read a file, write a file and copy a file using java.

ALGORITHM :

CREATE A FILE:

1. Create a class named createfile.2. Declare a variable f for the file.3. Assign the file name to the variable f.4. If file already exists print ‘File already exists’.5. Else create a file to the current directory by exception.6. Compile and save it.

READ A FILE:

1. Create a class named fileread.2. Open the file first that is required to read.3. Get the object of DataInputStream.4. BufferedReader is used for the Buffered Input character condition stream.5. Read the file line by line using while loop condition.6. Print the content on the console or display.7. Close the input stream.

WRITE A FILE:

1. Create a class named filewriter.2. Use BufferedReader for Buffered Input character.3. Enter the file name to create.4. If not exists create a new file using Boolean.5. BufferedWriter is used to buffered output character stream.6. Close the output stream.

COPY A FILE

Page 18: Ip Lab Manual

1. Create a class name copyfile.2. Open the input stream and output stream for copying the file.3. Mention the length of the stream using by bytelen.4. Write the contents in the file.5. Close the input stream and output stream.6. Display file copied.7. Using exception handling, if file not found throws the exception and exit.8. Catch the exception and display that get message.9. Using switch case statement, to copy the contents of file1 to file2 and also give the default

condition.

PROGRAM:CREATE A FILE

Page 19: Ip Lab Manual

import java.io.*;public class CreateFile1

public static void main(String []args)throws IOException{File f;f=new File("myfile.txt");if(!f.exists()){f.createNewFile();System.out.println("Newfile\"myfile.txt\"has been created to the current directory");}elseSystem.out.println("The specified file is already exist");}}

READ A FILEimport java.io.*;class FileRead{public static void main(String args[]){try{FileInputStream fstream=new FileInputStream("textfile.txt");DataInputStream in=new DataInputStream(fstream);BufferedReader br=new BufferedReader(new InputStreamReader(in));String strLine;while((strLine=br.readLine())!=null){System.out.println(strLine);}in.close();}catch(Exception e){System.err.println("Error:"+e.getMessage());}}}

WRITE A FILE:

import java.io.*;public class FileWrite{public static void main(String []args)throws IOException{

Page 20: Ip Lab Manual

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));System.out.println("please enter the file name to create");String file_name=in.readLine();File file=new File(file_name);boolean exist=file.createNewFile();if(!exist){System.out.println("File already exists");System.exit(0);}else{FileWriter fstream=new FileWriter(file_name);BufferedWriter out=new BufferedWriter(fstream);out.write(in.readLine());out.close();System.out.println("File created Successfully");}}}COPY A FILE:import java.io.*;public class CopyFile{private static void copyfile(String srFile,String dtFile){try{File f1=new File(srFile);File f2=new File(dtFile);InputStream in=new FileInputStream(f1);OutputStream out=new FileOutputStream(f2,true);OutputStream ut=new FileOutputStream(f2);byte[] buf=new byte[1024];int len;while((len=in.read(buf))>0){out.write(buf,0,len);}in.close();out.close();System.out.println("File copied");}catch(FileNotFoundException ex){System.out.println(ex.getMessage()+"in the specified directory");

Page 21: Ip Lab Manual

System.exit(0);}catch(IOException e){System.out.println(e.getMessage());}}public static void main(String []args){switch(args.length){case 0:System.out.println("File has not mentioned");System.exit(0);case 1:System.out.println("Destination file has not mentioned");System.exit(0);case 2:copyfile(args[0],args[1]);System.exit(0);default: System.out.println("Multiple files are not allow");System.exit(0);}}}

OUTPUT:

Page 22: Ip Lab Manual

CREATE A FILE:

READ A FILE:

WRITE A FILE:

Page 23: Ip Lab Manual

COPY A FILE:

Page 24: Ip Lab Manual

RESULT:

Thus the program to create a file, read a file, write a file and copy a file was written and executed.

EX.NO:04 (a) CLIENT SERVER APPLICATION FOR CHAT USING TCP

Page 25: Ip Lab Manual

DATE:01/08/2012

AIM:

To chat with client and server application using TCP/IP protocols.

ALGORITHM:

SERVER APPLICATION:

1. Create a class TCPserver1.2. Declare an object for socket as s and declare it as null.3. Create the two variables is,is1 and declare it as null.4. Output stream also created and declare it as null.5. Give the address for the socket of server.6. Catch the exception e.7. In the try block, create the object for is,is1 and os.8. Using do while condition read the line by line of the content and then close the is and os.9. Display the exception if caught.

CLIENT APPLICATION:

1. Create the class TCPclient1.2. Declare an object for socket as c and declare it as null.3. Create the variables for input stream is and is1 and declare it as null.4. Create an variable for print stream as os.5. Give the IP address for client c.6. Catch the exception e.7. Create the object for os,is,is1 in try block.8. Using do while condition read the content line by line.9. Close the input and output stream.10. 10.Display the exception if caught.

PROGRAM:

Page 26: Ip Lab Manual

TCPserver1.javaimport java.net.*;import java.io.*;public class TCPserver1{public static void main(String arg[]){ServerSocket s=null;String Line;DataInputStream is=null,is1=null;PrintStream os=null;Socket c=null;try{s=new ServerSocket(9999);}catch(IOException e){System.out.println(e);}try{c=s.accept();is=new DataInputStream(c.getInputStream());is1=new DataInputStream(System.in);os=new PrintStream(c.getOutputStream());do{Line=is.readLine();System.out.println("client"+Line);System.out.println("Server");Line=is1.readLine();os.println(Line);}while(Line.equalsIgnoreCase("quit")==false);is.close();os.close();}catch(IOException e){System.out.println(e);}}}

TCPclient1.java

Page 27: Ip Lab Manual

import java.net.*;import java.io.*;public class TCPclient1{public static void main(String args[]){Socket c=null;String Line;DataInputStream is,is1;PrintStream os;try{c=new Socket("127.0.0.1",9999);}catch(IOException e){System.out.println(e);}try{os=new PrintStream(c.getOutputStream());is=new DataInputStream(System.in);is1=new DataInputStream(c.getInputStream());do{System.out.println("client");Line=is.readLine();os.println(Line);System.out.println("server"+is1.readLine());}while(Line.equalsIgnoreCase("quit")==false);is1.close();os.close();}catch(IOException e){System.out.println("socket closed! Message is passing over");}}}

Page 28: Ip Lab Manual

OUTPUT:ServerC:\Program Files\Java\jdk1.5.0\bin>javac TCPserver1.javaNote: TCPserver1.java uses or overrides a deprecated API.Note: Recompile with -deprecation for details.C:\Program Files\Java\jdk1.5.0\bin>java TCPserver1Client: Hai ServerServer:Hai ClientClient: How are youServer:FineClient: quitServer:quitClientC:\Program Files\Java\jdk1.5.0\bin>javac TCPclient1.javaNote: TCPclient1.java uses or overrides a deprecated API.Note: Recompile with -deprecation for details.C:\Program Files\Java\jdk1.5.0\bin>java TCPclient1Client:Hai ServerServer: Hai ClientClient:How are youServer: FineClient:quit

Page 29: Ip Lab Manual

RESULT:

Thus the program Using TCP by client server application for chat written and executed successfully.

Page 30: Ip Lab Manual

EX.NO:04(b) IMPLEMENTATION OF TCP/IP ECHO

AIM:

To implement TCP/IP Echo application.

ALGORITHM:

SERVER APLLICATION:

1. Create the class EServer.2. Create an object s for socket of server and declare it as null.3. Create an object ps,is for print and input stream.4. Declare the object c for client as null.5. Give the IP address of the server in the try block.6. Catch the exception e.7. Create an object for input stream and print stream in try.8. Using while condition, read the content line by line.9. Display the exception if caught.

CLIENT APPLICATION:

1. Create the class EClient.2. Create an object c for client socket and declare it as null.3. Create an object for input stream is,is1 and printstream os.4. Give the IP address for the client.5. Catch the exception e.6. Create an object for output stream os and input stream is,is1 in the try block.7. Using while read the content line by line.8. Display the exception if caught.9. Display the message socket closed.

PROGRAM:

Page 31: Ip Lab Manual

EServer.javaimport java.net.*;import java.io.*;public class Eserver{public static void main(String args[]){ServerSocket s=null;String Line;DataInputStream is;PrintStream ps;Socket c=null;try{s=new ServerSocket(9000);}catch(IOException e){System.out.println(e);}try{c=s.accept();is=new DataInputStream(c.getInputStream());ps=new PrintStream(c.getOutputStream());while(true){Line=is.readLine();ps.println(Line);}}catch(IOException e){System.out.println(e);}}}

EClient.java

Page 32: Ip Lab Manual

import java.net.*;import java.io.*;public class Eclient{public static void main(String args[]){Socket c=null;String Line;DataInputStream is,is1;PrintStream os;try{c=new Socket("127.0.0.1",9000);} catch(IOException e){System.out.println(e);}try{os=new PrintStream(c.getOutputStream());is=new DataInputStream(System.in);is1=new DataInputStream(c.getInputStream());while(true){System.out.println("client:");Line=is.readLine();os.println(Line);System.out.println("server:"+is1.readLine());}}catch(IOException e){System.out.println("socket closed!");}}}

Output:

Page 33: Ip Lab Manual

Server:C:\Program Files\Java\jdk1.5.0\bin>javac EServer.javaNote: EServer.java uses or overrides a deprecated API.Note: Recompile with -deprecation for details.C:\Program Files\Java\jdk1.5.0\bin>java EServerC:\Program Files\Java\jdk1.5.0\bin>Client:C:\Program Files\Java\jdk1.5.0\bin>javac EClient.javaNote: EClient.java uses or overrides a deprecated API.Note: Recompile with -deprecation for details.C:\Program Files\Java\jdk1.5.0\bin>java EClientClient:Hai ServerServer:Hai ServerClient:HelloServer:HelloClient:endServer:endClient:dsSocket Closed!

Page 34: Ip Lab Manual

RESULT:

Thus the program for implementation of TCP/IP Echo was written and executed successfully.

Page 35: Ip Lab Manual

EX.NO:04 (c) PROGRAMS USING SIMPLE UDP

AIM:

To write a client-server application for chat using UDP

ALGORITHM:

CLIENT

1. Include necessary package in java

2. To create a socket in client to server.

3. The client establishes a connection to the server.

4. The client accept the connection and to send the data from client to server and vice versa

5. The client communicate the server to send the end of the message

6. Stop the program.

SERVER

1. Include necessary package in java

2. To create a socket in server to client

3. The server establishes a connection to the client.

4. The server accept the connection and to send the data from server to client and vice versa

5. The server communicate the client to send the end of the message

6. Stop the program.

Page 36: Ip Lab Manual

PROGRAM :

UDPserver.java

import java.io.*;import java.net.*;class UDPserver{ public static DatagramSocket ds;

public static byte buffer[]=new byte[1024];public static int clientport=789,serverport=790;public static void main(String args[])throws Exception{

ds=new DatagramSocket(clientport);System.out.println("press ctrl+c to quit the program");BufferedReader dis=new BufferedReader(new InputStreamReader(System.in));InetAddress ia=InetAddress.getByName("localhost");while(true){

DatagramPacket p=new DatagramPacket(buffer,buffer.length);ds.receive(p);String psx=new String(p.getData(),0,p.getLength());System.out.println("Client:" + psx);System.out.println("Server:");String str=dis.readLine();if(str.equals("end"))

break;buffer=str.getBytes();ds.send(new DatagramPacket(buffer,str.length(),ia,serverport)); }}}

UDPclient.javaimport java .io.*;import java.net.*;class UDPclient{

public static DatagramSocket ds;public static int clientport=789,serverport=790;public static void main(String args[])throws Exception{

byte buffer[]=new byte[1024]; ds=new DatagramSocket(serverport); BufferedReader dis=new BufferedReader(new InputStreamReader(System.in));

System.out.println("server waiting");InetAddress ia=InetAddress.getByName("10.0.200.36");while(true){

Page 37: Ip Lab Manual

System.out.println("Client:");String str=dis.readLine();if(str.equals("end"))

break;buffer=str.getBytes();ds.send(new DatagramPacket(buffer,str.length(),ia,clientport));DatagramPacket p=new DatagramPacket(buffer,buffer.length);ds.receive(p);String psx=new String(p.getData(),0,p.getLength());System.out.println("Server:" + psx);

}}

}

Page 38: Ip Lab Manual

OutputServerC:\Program Files\Java\jdk1.5.0\bin>javac UDPserver.javaC:\Program Files\Java\jdk1.5.0\bin>java UDPserverpress ctrl+c to quit the programClient:Hai ServerServer:Hello ClientClient:How are YouServer:I am Fine what about youClient

C:\Program Files\Java\jdk1.5.0\bin>javac UDPclient.java

C:\Program Files\Java\jdk1.5.0\bin>java UDPclientserver waitingClient:Hai ServerServer:Hello ClieClient:How are YouServer:I am Fine wClient:end

Page 39: Ip Lab Manual

RESULT:

Thus the above program a client-server application for chat using UDP was executed and

successfully

Page 40: Ip Lab Manual

EX:NO:5 JAVA APPLET PROGRAM FOR CALCULATOR

AIM:

To write a java applet program for calculator.

ALGORITHM:

1. Create the subclass cal.2. Create an interface action listener using the keyword implements.3. Declare the variables t1,v1,v2 result for int text field respectively.4. Create a variable b for button and assign the value.5. Create the button for add,sub,mul,div,mod,clear and EQ.6. Create the variable OP as char type.7. Create the variable k for setting the color and also assign the value for text field and for

gridlayout gl and assign the value.8. Create the variable t1 using ‘this’ keyword.9. Add the button and declare it as t1.

10. Use ‘for’ for interface and add all the commands.

11. In the interface ActionListener, declare str and char and else if condition to perform the action

specified.

Page 41: Ip Lab Manual

PROGRAM:import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="Cal" width=300 height=300></applet>*/public class Cal extends Appletimplements ActionListener{String msg="";int v1,v2,result;TextField t1;Button b[]=new Button[10];Button add,sub,mul,div,clear,mod,EQ;char OP;public void init(){Color k=new Color(120,89,90);setBackground(k);t1=new TextField(10);GridLayout gl=new GridLayout(4,5);setLayout(gl);for(int i=0;i<10;i++){b[i]=new Button(""+i);}add=new Button("add");sub=new Button("sub");mul=new Button("mul");div=new Button("div");mod=new Button("mod");clear=new Button("clear");EQ=new Button("EQ");t1.addActionListener(this);add(t1);for(int i=0;i<10;i++){add(b[i]);}add(add);add(sub);add(mul);

Page 42: Ip Lab Manual

add(div);add(mod);add(clear);add(EQ);for(int i=0;i<10;i++){b[i].addActionListener(this);}add.addActionListener(this);sub.addActionListener(this);mul.addActionListener(this);div.addActionListener(this);mod.addActionListener(this);clear.addActionListener(this);EQ.addActionListener(this);}public void actionPerformed(ActionEvent ae){String str=ae.getActionCommand();char ch=str.charAt(0);if(Character.isDigit(ch))t1.setText(t1.getText()+str);elseif(str.equals("add")){v1=Integer.parseInt(t1.getText());OP='+';t1.setText("");}else if(str.equals("sub")){v1=Integer.parseInt(t1.getText());OP='-';t1.setText("");}else if(str.equals("mul")){v1=Integer.parseInt(t1.getText());OP='*';t1.setText("");}else if(str.equals("div")){v1=Integer.parseInt(t1.getText());

Page 43: Ip Lab Manual

OP='/';t1.setText("");}else if(str.equals("mod")){v1=Integer.parseInt(t1.getText());OP='%';t1.setText("");}if(str.equals("EQ")){v2=Integer.parseInt(t1.getText());if(OP=='+')result=v1+v2;else if(OP=='-')result=v1-v2;else if(OP=='*')result=v1*v2;else if(OP=='/')result=v1/v2;else if(OP=='%')result=v1%v2;t1.setText(""+result);}if(str.equals("clear")){t1.setText("");}}

Page 44: Ip Lab Manual

OUTPUT:

}

Page 45: Ip Lab Manual

RESULT:

Thus the java applet program that allows the user to draw lines, rectangles and ovals and create a calculator was written and executed successfully.

Page 46: Ip Lab Manual

EX NO:8 PROGRAMS USING RPC / RMI

Page 47: Ip Lab Manual

AIM:

To implement the program using RMI

ALGORITHM:

1. Start the program and to include necessary packages

2. Using Add client to get the two values

3.Using Add server() to implement and Call the Add server impl

4.Using public interface to call the program in remotely

5.Finally to call and compile all the sub program

6.To Execute Start RMI registry

7.Stop the program

PROGRAM:

Page 48: Ip Lab Manual

ADD CLIENT:import java.rmi.*;public class AddClient{

public static void main(String args[]){

try{

String addServerURL="rmi://"+args[0]+"/AddServer";AddServerIntf addServerIntf=(AddServerIntf)Naming.lookup(addServerURL);

System.out.println("the first number is"+args[1]);double d1=Double.valueOf(args[1]).doubleValue( );System.out.println("the Second number is"+args[2]);double d2=Double.valueOf(args[2]).doubleValue();System.out.println("the sum is "+addServerIntf.add(d1,d2));

}catch(Exception e){

System.out.println("Exception:"+e);}

}}ADD SERVERimport java.net.*;import java.rmi.*;public class AddServer {public static void main(String args[])

{try{

AddServerImpl addServerImpl=new AddServerImpl();Naming.rebind("AddServer",addServerImpl);

}catch(Exception e){

System.out.println("Exception :"+e);}}

}

ADD SERVERIMPL:import java.rmi.*;

Page 49: Ip Lab Manual

import java.rmi.server.*;public class AddServerImpl extends UnicastRemoteObject implements AddServerIntf{

public AddServerImpl()throws RemoteException{}public double add(double d1,double d2)throws RemoteException{

return d1+d2;}

}

ADDSERVERINTF:

import java.rmi.*;public interface AddServerIntf extends Remote{

double add(double d1,double d2)throws RemoteException;}

OUTPUT:

Page 50: Ip Lab Manual
Page 51: Ip Lab Manual

RESULT:

Thus the Above program RMI was executed and successfully.

EX NO: 9 ON-LINE EXAM USING SERVLETS

Page 52: Ip Lab Manual

Date:

AIM

Develop an Servlet program to conduct online examination.

ALGORITHM:

1. Create a database , add a table with the following fields

Field type

Option1 text 250

Option2 text 250

Option3 text 250

Option4 text 250

Answer text 250

Question text 250

2. Insert 10 records

3. Create a system DSN in the ODBC panel (onlineexam)

4. compile the Source

5. invoke the page and test

PROGRAM

Page 53: Ip Lab Manual

package test;

import java.io.*;

import java.net.*;

import java.sql.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class Exam extends HttpServlet {

Connection ConnRecordset;

PreparedStatement StatementRecordset;

ResultSet Recordset;

protected void processRequest(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

response.setContentType("text/html");

PrintWriter out = response.getWriter();

int total=0;

out.print("<H3>Online Exam</h3>");

out.print("<Table border=1>");

int qno=1;

out.print("<form name='form1' method='post' action='score'>");

try{

while (Recordset.next())

{

out.print("<tr><td>Question no"+qno+"</td><td>"+Recordset.getString(6)+"</td></tr>");

out.print("<tr><td><input type='radio' name='opt"+qno+"' value='1'>"+"</td><td>"+Recordset.getString(1)+"</td></tr>");

out.print("<tr><td><input type='radio' name='opt"+qno+"' value='2'>"+"</td><td>"+Recordset.getString(2)+"</td></tr>");

out.print("<tr><td><input type='radio' name='opt"+qno+"' value='3'>"+"</td><td>"+Recordset.getString(3)+"</td></tr>");

Page 54: Ip Lab Manual

out.print("<tr><td><input type='radio' name='opt"+qno+"' value='4'>"+"</td><td>"+Recordset.getString(4)+"</td></tr>");

qno=qno+1;

}

out.print("<tr></tr><tr><td><input type='submit' name='Submit' value='Submit'>");

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

out.close();

Recordset.close();

StatementRecordset.close();

ConnRecordset.close();

}

catch(SQLException sqe)

{

out.print("Error"+sqe);

}

}

protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException

{

try{

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

ConnRecordset=DriverManager.getConnection("jdbc:odbc:onlineexam");

StatementRecordset = ConnRecordset.prepareStatement("SELECT * FROM test");

Recordset = StatementRecordset.executeQuery();

}

catch(Exception e){}

processRequest(request, response); } }

OUTPUT

Page 55: Ip Lab Manual
Page 56: Ip Lab Manual

RESULT:

Thus servlet based online exam had been developed and tested

EX NO:9 HTML PROGRAM TO CREATE ONLINE BOOK STORE

AIM:

Page 57: Ip Lab Manual

AIM:

To develop a html Program to implement the online Book Store application.

ALGORITHM:

1. Start the Program.

2. Create the html Programs using notepad.

3. Browse the location of the file in the local disk.

4. Enter the URL in the web browser.

5. Run the web browser.

6. Enter into the Login Page. Enter the id and password. If the id and password is valid, the Book

store web page is displayed.

7. Otherwise, error message will be displayed.

8. Stop the program.

PROGRAM:

Main page:

<html>

Page 58: Ip Lab Manual

<head>

<title>home page</title>

</head>

<body>

<center><b><h1>welcome to amazon.com</h1></b><br><br>

<form method="post"action="login.html">

<input type="submit"value="click">registration user login hear

</center>

</body>

</html>

Login page:

<html>

<head>

<title>login page</title>

</head>

<body>

<center>

<form method="post" action="login.html">

<p><strong>name:</strong>

<input type="text" name="username" size="25">

</p>

<p><strong>password</strong>

<input name="pass" type="password" size="6"></p>

<p><strong>male</strong>

<input type="radio" value="male"<hacked>&nbsp&nbsp</p>

<p><strong>female</strong>

<option><input type="radio" value="female"<hacked>&nbsp;</p>

<input type="submit" value="submit">&nbsp&nbps

Page 59: Ip Lab Manual

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

<a href="registration.html">new users register hear </a>

</form>

</center>

</body>

</html>

Books Catalog:

<html>

<head>

<title>books catalog</title>

</head>

<body>

<center><h1><p>welcome to books catalog</p></h1>

<table border="1"width="25%"height="50%">

<tr>

<th>computers</th>

<th>electronics</th>

<th>biotech</th>

<th>mechanical</th>

</tr>

<tr>

<td>

</body>

</html>

OUTPUT:

Page 60: Ip Lab Manual
Page 61: Ip Lab Manual
Page 62: Ip Lab Manual

RESULT:

Thus the HTML Program to implement the online Book Store application was written and

executed successfully.

Page 63: Ip Lab Manual

EX NO:9 SCHEMATIC DESIGN USING XML

(a). DISPLAY RECEIPIENT DETAILS USING XML - DTD

AIM:

To write an XML DTD Program to Display Recipient Details for purchasing of Books.

ALGORITHM:

1. Start the Program.

2. Create the xml, Document type definition Programs using notepad.

3. Browse the location of the file in the local disk.

4. Enter the URL in the web browser.

5. Run the web browser.

6. Display the welcome message for web page with dynamic effects.

7. Stop the program.

Page 64: Ip Lab Manual

PROGRAM:

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

<! DOCTYPE purchase Order SYSTEM "po.dtd">

<purchase Order order Date="07.23.2001" >

<recipient country="USA">

<name>RAVIKRISHNA</name>

<street>7G,RAINBOW COLONY,ADYAR</street>

<city>CHENNAI-28</city>

<state>TAMILNADU</state>

</recipient>

<order>

<cd artist="Brooks Williams" title="Little Lion" />

<cd artist="David Wilcox" title="What you whispered" />

</order>

</purchase Order>

Po.dtd:

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

<!ELEMENT purchaseOrder (recipient,order)>

<!ELEMENT recipient (name,street,city,state)>

<!ELEMENT name (#PCDATA)>

<!ELEMENT street (#PCDATA)>

<!ELEMENT city (#PCDATA)>

<!ELEMENT state (#PCDATA)>

<!ELEMENT order (cd)+>

<!ELEMENT cd EMPTY>

<!ATTLIST purchaseOrder

orderDate CDATA #REQUIRED >

<!ATTLIST recipient

Page 65: Ip Lab Manual

country CDATA #REQUIRED >

<!ATTLIST cd artist CDATA #REQUIRED

title CDATA #REQUIRED>

po.html:

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"po.dtd"">

<Html>

<head COLOR: BLACK><h1 style="color: WHITE">

<MARQUEE DIRECTION="right"><CENTER>PURCHASE ORDER </CENTER> </MARQUEE>

</H1>

<img src="C:\Documents and Settings\Administrator\Desktop\ATT4864414.jpg"

height=100 ,width=100>

<title> RECIPIENT DETAILS </title>

</head>

<body style="background-color: BLACK"> <H3 STYLE="COLOR: BLUE">

<MARQUEE DIRECTION="UP">

<p> BOOK DETAIL<BR>

AUTHOR: Brooks Williams,<BR>David Wilcox<BR>BOOK NAME: Little Lion,<br>What you

whispered

</MARQUEE></p>

<p><marquee direction="UP"><h3 style="color: red">RECIPIENT DETAILS</P></marquee>

<UL>

<LI>NAME: RAVIKRISHNA

<LI>STREET:7G,RAINBOW COLONY,ADYAR

<LI>CITY:CHENNAI-28

<LI>STATE:TAMILNADU

</UL>

</body>

</html>

Page 66: Ip Lab Manual

OUTPUT:

Page 67: Ip Lab Manual

RESULT:

Thus the Xml DTD Program to Display Recipient details for purchasing of books was written and

executed successfully.

Page 68: Ip Lab Manual

Ex.No:11(b) DISPLAY THE DOCUMENT USING XML - XSL

Date:

AIM:

To write an XML XSL Program to Display the titles of the documents.

ALGORITHM:

1. Start the Program.

2. Create the xml, Document type definition and xsl programs using notepad.

3. Browse the location of the file in the local disk.

4. Enter the URL in the web browser.

5. Run the web browser.

6. Display the web page with effects.

7. Stop the program.

Page 69: Ip Lab Manual

PROGRAM:

DOC.DTD

<! ELEMENT doc (title, chapter*)>

<!ELEMENT chapter (title, (para|note)*, section*)>

<! ELEMENT section (title, (para|note)*)>

<! ELEMENT title (#PCDATA|emph)*>

<! ELEMENT para (#PCDATA|emph)*>

<! ELEMENT note (#PCDATA|emph)*>

<! ELEMENT emph (#PCDATA|emph)*>

DOC.XSL

<xsl:stylesheet version="1.0"

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

xmlns="http://www.w3.org/TR/xhtml1/strict">

<xsl:strip-space elements="doc chapter section"/>

<xsl:output

method="xml"

indent="yes"

encoding="iso-8859-1"/>

<xsl:template match="doc">

<html>

<head>

<title>

<xsl:value-of select="title"/>

</title>

</head>

<body>

<xsl:apply-templates/>

</body>

</html>

</xsl:template>

<xsl:template match="doc/title">

<h1>

<xsl:apply-templates/>

Page 70: Ip Lab Manual

</h1>

</xsl: template>

<xsl:template match="chapter/title">

<h2>

<xsl:apply-templates/>

</h2>

</xsl:template>

<xsl:template match="section/title">

<h3>

<xsl:apply-templates/>

</h3>

</xsl:template>

<xsl:template match="para">

<p>

<xsl:apply-templates/>

</p>

</xsl:template>

<xsl:template match="note">

<p class="note">

<b>NOTE: </b>

<xsl:apply-templates/>

</p>

</xsl:template>

<xsl:template match="emph">

<em>

<xsl:apply-templates/>

</em>

</xsl:template>

</xsl:stylesheet>

Page 71: Ip Lab Manual

DOC.XML

<!DOCTYPE doc SYSTEM "doc.dtd">

<doc>

<title>Document Title</title>

<chapter>

<title>Chapter Title</title>

<section>

<title>Section Title</title>

<para>This is a test.</para>

<note>This is a note.</note>

</section>

<section>

<title>Another Section Title</title>

<para>This is <emph>another</emph> test.</para>

<note>This is another note.</note>

</section>

</chapter>

</doc>

DOC.HTML

<?xml version="1.0"?>

<?xml-stylesheet type="text/xsl" href="doc.xsl"?><html xmlns="http://www.w3.org/TR/xhtml1/strict">

<head>

<title>Document Title</title>

</head>

<body>

<h1>Document Title</h1>

<h2>Chapter Title</h2>

<h3>Section Title</h3>

<p>This is a test.</p>

<p class="note">

<b>NOTE: </b>This is a note.</p>

<h3>Another Section Title</h3>

<p>This is <em>another</em> test.</p>

Page 72: Ip Lab Manual

<p class="note">

<b>NOTE: </b>This is another note.</p>

</body>

</html>

Page 73: Ip Lab Manual

OUTPUT:

Page 74: Ip Lab Manual

RESULT:

Thus the Xml XSL Program to Display the titles of the documents was written and executed

successfully.