You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by rajesh srinivasan <sp...@yahoo.co.in> on 2008/10/12 10:39:54 UTC

full ip lab programs

//Vehicles.html             external stylesheet

<html>
<head>
<title>cars</title>
</head>
<body>
<link rel="stylesheet" type="text/css" href="e:\ip progs\style1.css">
<h1><center>Hunting for cars??</center></h1>
<li><h1>Hyundai</h1><a href="hyundai.html"><img src="e:\ip progs\hyundai.jpg"></a>
<li><h2>Mahindra</h2><a href="mahi.html"><img src="e:\ip progs\mahi.jpg"></a>
<li><h3>Tata</h3><a href="tata.html"><img src="e:\ip progs\tata.jpg"></a>
<li><h4>Toyota</h4><a href="toyota.html"><img src="e:\ip progs\toyota.jpg"></a>
</body>
</html>



//style1.css

body{background:yellow}
h1{color:green}



//Hyundai.html            inline stylesheet

<html>
<head><title>hyundai</title></head>
<body text="black">
<center>HYUNDAI</CENTER>
<li><h1 style="color:red">The first Hyundai company was founded in 1947  </li>
<li> the world's 5th largest automaker. </li>
</body>
</html>




//mahindra.html                            grouping elements

<html>
<head>
<style type="text/css">
h2,h3,h4
{
color:red
}
</style>
</head>
<body text="black">
<center>mahindra</center>
<li><h2>Mahindra & Mahindra is a part of the Mahindra Group  </h2></li>
<li> <h3>established in 1945 to manufacture general-purpose utility vehicles.</h3></li>
</body>
</html>


                                                


//tata.html                                    embedded stylesheet

<html>
<head>
<style type="text/css">
p {color:red}
</style>
</head>
<body bgcolor="yellow">
<center>TATA</center>
<p>True to the tradition of the Tata Group,
<br> Tata Motors is committed in letter and spirit to
<br> Corporate Social Responsibility. 
<br>It is a signatory to the United Nations Global Compact,<br>
 and is engaged in community and social initiatives on labour<br>
 and environment standards in compliance with the principles of 
<br>the Global Compact.
</body>
</html>



//Toyota.html            importing stylesheets

<html>
<head>
<style type="text/css" media="all">
@import "style1.css";
</style> 
</head>
<body text="black" >
<center><h1>TOYOTA</h1></center><br>
<li> branded japan make</li>
<li>fuel effecient</li>
</body>
</html>



india:

<html>
<body bgcolor=”black” >
<p>click here to view each state</p>
<img src="c:\indiamap.gif"
width="432" height="468"
usemap="#indiamap">
<map id="indiamap" name="indiamap">

<area shap="rect"
coords="124,402,137,447"
alt="TN 
11th largest state in India
covers an are of 130,058 sq kms
has abt 31 districts."
href="c:\tn.html">
</map>
</body>
</html>

//TN

<html>
<head>tamil nadu map</head>
<title>TAMIL NADU</title>
<img src="tn.gif"
width="150" height="125">
<a href="indiamap.html">full map</a>
</html>





//awt
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code ="awt" width=400 height=400></applet>*/
public class awt extends Applet implements ActionListener
{
TextField t1;
Button b;
Checkbox ch1;

public void init()
{
ch1= new Checkbox("check");
add(ch1);
t1 = new TextField(25);
add(t1);
b=new Button("button");
add(b);
b.addActionListener(this);
}


public void actionPerformed(ActionEvent e)
{

if(e.getSource()==b)
{
t1.setText("msg");
}
}


public boolean handleEvent(Event a) 
{
String msg="hi";
if(a.target==ch1)
{
t1.setText(msg);
}
return (true);
}
}





import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*     
<applet code="awt1.class" width=250 height=150>
</applet>
*/
public class awt1 extends Applet implements ActionListener,ItemListener
{
String msg=" ";
CheckboxGroup gr= new CheckboxGroup();
Label input1p= new Label("input1");
Label input2p= new Label("input2");
TextField input1=new TextField(12);
TextField input2=new TextField(12);
Checkbox ch1= new Checkbox("add",gr,true);
Checkbox ch2= new Checkbox("sub",gr,false);
Checkbox ch3= new Checkbox("multiply",gr,false);
Button ok= new Button("ok");
Button cancel= new Button("cancel");

public void init()
{
String msg=" ";
int sum=0;
add(input1p);
add(input1);
add(input2p);
add(input2);



add(ch1);
add(ch2);
add(ch3);
add(ok);
add(cancel);

ch1.addItemListener(this);
ch2.addItemListener(this);
ch3.addItemListener(this);
input1.addActionListener(this);
input2.addActionListener(this);
ok.addActionListener(this);
cancel.addActionListener(this);

}


public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
if(str.equals("ok"))
repaint();
}
public void itemStateChanged(ItemEvent e)
{
repaint();
                                        
}

public void paint(Graphics g)
{

int sum=0;
msg=gr.getSelectedCheckbox().getLabel();
if(msg.equals("add"))
{
String t1=input1.getText();
String t2=input2.getText();
int x=Integer.parseInt(t1);
int y=Integer.parseInt(t2);
sum=x+y;
msg="addition of two numbers"+sum;
}
 else if(msg.equals("sub"))
{

String str2;
String t1=input1.getText();
String t2=input2.getText();
int x=Integer.parseInt(t1);
int y=Integer.parseInt(t2);
sum=x-y;
msg="subtraction of two numbers"+sum;

}
else if(msg.equals("multiply"))
{
String t1=input1.getText();
String t2=input2.getText();
int x=Integer.parseInt(t1);
int y=Integer.parseInt(t2);
sum=x*y;
msg="multiplication of two numbers"+sum;
}
g.drawString(msg,30,130);
}
 }




import java.awt.*;
import java.applet.*;
/*<applet code =grid.class width =300 height=100>
</applet>
*/
public class grid extends Applet
{
String msg="";
static final int  n=4;
public void init()
{
setLayout(new GridLayout(n,n));
for(int i=0;i<n;i++)
 {
for(int j=0;j<n;j++)
 {
int k=i*n+j;
if(k>=0)
add(new Button(" "+k));
 }
 }
}
}




TCP CHAT APPLICATION
SOURCE CODE

//TCP server
import java.net.*;
import java.io.*;
public class sserver
{
public static void main(String a[])throws Exception
{
ServerSocket ssc=new ServerSocket(1000);
Socket s=ssc.accept();
DataInputStream d=new DataInputStream(System.in);
DataInputStream dt=new DataInputStream(s.getInputStream());
PrintStream ps=new PrintStream(s.getOutputStream());
String res=null,req=null;
while(true)
{
res=dt.readLine();
System.out.println("clientresponse         "+res);
req=d.readLine();
ps.println(req);
}
}
}

//TCP client

import java.net.*;
import java.io.*;
public class sclient
{
public static void main(String a[])throws Exception
{
Socket s=new Socket("127.0.0.1",1000);
DataInputStream d=new DataInputStream(System.in);
DataInputStream dt=new DataInputStream(s.getInputStream());
PrintStream ps=new PrintStream(s.getOutputStream());
String res=null,req=null;
ps.println("client Ready");
while(true)
{
res=dt.readLine();
System.out.println("serverresponse             "+res);
req=d.readLine();
ps.println(req);
}
}
}





UDP CHAT APPLICATION
SOURCE CODE :
//UDP serverApp
import java.net.*;
import java.io.*;
public class server
{
public static void main(String args[])throws Exception
{
DatagramSocket ioSocket;
String a="localhost";
String u;
byte sendBuffer[]=new byte[128];
DatagramPacket sendPacket = new DatagramPacket(sendBuffer,128);
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int ioPort = 111, receiverPort=ioPort;
if(args.length>0)
a=args[0];
else
a="localhost";
if(a.equals("localhost"))
receiverPort=222;
try {
ioSocket=new DatagramSocket(ioPort);
}
catch(Exception e)
{
ioPort = 222;
receiverPort=111;
ioSocket = new DatagramSocket(ioPort);
}
System.out.println("chat on port"+ioPort+"ctrl z to quit ");
new receiver(ioSocket);
while((u=in.readLine())!=null)
{
sendBuffer=u.getBytes();
sendPacket=new 

DatagramPacket(sendBuffer,sendBuffer.length,InetAddress.getByName(a),receiverPort);
ioSocket.send(sendPacket);
}
System.exit(0);
}}
class receiver implements Runnable
{
DatagramSocket ioSocket;
receiver(DatagramSocket ioSocket)
{
this.ioSocket=ioSocket;
               
new Thread(this).start();
}
public void run()
{
byte receiverBuffer[]=new byte[128];
DatagramPacket receivePacket = new DatagramPacket(receiverBuffer,108);
while(true)
{
try { ioSocket.receive(receivePacket); }
catch(Exception e)
{
}
System.out.println("received "  +new 

String(receivePacket.getData(),0,receivePacket.getLength()));
}
}
}


COLOR PALETTE
SOURCE CODE :

//colo.java
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.lang.*;
/*
<applet code="colo.java" height=600 width=600>
</applet>
*/
public class colo extends Applet implements ActionListener
{
int r,g,b;
Panel p1,p2;
TextArea t1;
CheckboxGroup cbg=new CheckboxGroup();
Checkbox b1,b2;
public void init()
{
setLayout(null);
p1=new Panel();
p2=new Panel();
t1=new TextArea(10,20);
b1=new Checkbox("backcolor",cbg,true);
b2=new Checkbox("forecolor",cbg,false);
p2.add(t1);
p2.add(b1);
p2.add(b2);
p1.setLayout(new GridLayout(16,16,0,0));
Button bn[]=new Button[256];
for(int i=0;i<=255;i++)
{
r=(int)Math.ceil(Math.random()*255);
g=(int)Math.ceil(Math.random()*255);
b=(int)Math.ceil(Math.random()*255);
Color c= new Color(r,g,b);
bn[i]=new Button(" ");
p1.add(bn[i]);
bn[i].setBackground(c);
bn[i].addActionListener(this);
}
add(p1);
add(p2);
p1.setBounds(10,10,250,350);
p2.setBounds(250,10,200,200);
}


                                    


public void actionPerformed(ActionEvent e)                                             
{
if(b1.getState())
t1.setBackground((((Button)(e.getSource())).getBackground()));
if(b2.getState())
t1.setForeground((((Button)(e.getSource())).getBackground()));
}
}



DOWNLOADING HOMEPAGE
SOURCE CODE :

//gpt.java
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
class gpt extends JFrame implements ActionListener
{
JFrame fa= new JFrame();
JTextField t=new JTextField(15);
JButton goButton=new JButton("go");
JButton deButton=new JButton("details");
JEditorPane pane=new JEditorPane();
JPanel jp=new JPanel();
public gpt()
{
goButton.addActionListener(this);
deButton.addActionListener(this);
jp.add(t);
jp.add(goButton);
jp.add(deButton);
pane.setEditable(false);
fa.getContentPane().add(jp,BorderLayout.NORTH);
fa.getContentPane().add(pane,BorderLayout.SOUTH);
fa.setSize(700,700);
fa.setTitle("s1 cse A");
fa.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==goButton)
{
try
{
URL url=new URL(t.getText().trim());
pane.setPage(url);
}
catch(Exception ex){}
}
if(e.getSource()==deButton)
{
try

                                
{
morel mo=new morel(this);                                    

    
}                                        
catch(Exception ex1){}
}
}
public static void main(String args[])
{
gpt myb=new gpt();
}
}


//Morel.java

import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Date;
import java.io.*;
class morel extends Frame implements ActionListener
{
gpt bre;
TextArea ta1=new TextArea(10,30);
Button b= new Button("back");
public morel(gpt u)
{
setLayout(new FlowLayout());
setSize(400,400);
add(ta1);
add(b);
b.addActionListener(this);
setVisible(true);
this.bre=u;
setTitle(bre.t.getText()+":File details");
try
{
int e;
URL hp=new URL(bre.t.getText());
URLConnection hpcon=hp.openConnection();
ta1.setText(" ");
ta1.append("\n");
ta1.append("Content - Type :"+hpcon.getContentType());
ta1.append("\n");
ta1.append("express: "+hpcon.getExpiration());
ta1.append("\n");
ta1.append("Last Modified :"+new Date(hpcon.getLastModified()));
ta1.append("\n");
int len=hpcon.getContentLength();
ta1.append("Content-Length: "+len);
}    
catch(Exception w){}
}
public void actionPerformed(ActionEvent e)
{
this.dispose();
}
}
    

SOURCE CODE: 
//FtpServer:
import java.io.*;
import java.io.DataInputStream;
import java.net.*;
import java.net.ServerSocket;
import java.net.Socket;
class fileserver
{
public static void main(String args[])
{
Fserver fs=new Fserver();
fs.start();
}
}
class Fserver extends Thread
{
public void run()
{
try
{
String response=" ";
ServerSocket ss=new ServerSocket(4001);
while(true)
{
Socket so=ss.accept();
DataInputStream d=new DataInputStream(so.getInputStream());
String filename=d.readLine();
so.close();
File f=new File(filename);
if(f.isFile()&&f.canRead())
{
BufferedReader bf=new BufferedReader(new FileReader(filename));
String temp;
while((temp=bf.readLine())!=null)
{
response=response+temp;
response=response+"/n";
so.close();
}
}
else
{
response="INVALID FILENAME ";
}
                                    
so=ss.accept();
PrintStream p=new PrintStream(so.getOutputStream());
p.print(response);
so.close();
}
}
catch(Exception e)
{
System.out.println("Error from Exception ");
}
}
}

//FTP Client:
import java.io.*;
import java.io.DataInputStream;
import java.net.*;
import java.net.ServerSocket;
import java.net.Socket;
class Fileclient
{
public static void main(String args[])throws Exception
{
System.out.println("\n enter a file name");
Socket so=new Socket("localhost",4001);
DataInputStream d=new DataInputStream(System.in);
String filename=d.readLine();
PrintStream p=new PrintStream(so.getOutputStream());
p.print(filename);
so.close();
so=new Socket("localhost",4001);
DataInputStream dd=new DataInputStream(so.getInputStream());
String result;
while((result=dd.readLine())!=null)
{System.out.println(result);
}so.close();
}
}



    
import java.net.*;                                        
import java.io.*;
public class http2
{
public static void main(String args[])
{
try
{
String Request="c:/inferno.txt";
Socket client_Socket=new Socket(Request,80);
System.out.println("the client is"+client_Socket);
Get_Web_Page(client_Socket);
}
catch(UnknownHostException e)
{
System.err.println("unknownHostException"+e.getMessage());
}
catch(IOException e)
{
System.err.println("IOException"+e.getMessage());
}}
public static void Get_Web_Page(Socket client_Socket)
{
try
{
DataOutputStream output=new DataOutputStream (client_Socket.getOutputStream());
DataInputStream input=new DataInputStream (client_Socket.getInputStream());
output.writeBytes("GET/HTTP/1.0\r\n\r\n");
String input_txt;
while((input_txt=input.readLine())!=null)
{
System.out.println(input_txt);
if(input_txt.indexOf("</HTML>")!=-1)
break;
}
output.close();
input.close();
client_Socket.close();
}
catch(Exception e)
{
System.err.println("Exception :"+e.getMessage());
}
}}




SOURCE CODE:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class serve extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException 

,ServletException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>My first servlet</title>");
out.println("<body>");
out.println("<h1>My first servlet</h1>");
out.println("<h2>Hello!!!!!!!!!</h2>");
out.println("<h3>bye</h3>");
out.println("</body>");
out.println("</html>");
out.close();
}
}

//WEB[XML Document]
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" 

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

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <servlet>
        <servlet-name>serve</servlet-name>
        <servlet-class>serve</servlet-class>
        </servlet>

    <servlet-mapping>
        <servlet-name>serve</servlet-name>
        <url-pattern>/serve</url-pattern>
    </servlet-mapping>
    
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
</web-app>





SOURCE CODE:

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class student extends HttpServlet
{
String message,Seatno,Name,ans1,ans2,ans3,ans4,ans5;
int Total;
Statement stmt=null;
ResultSet rs=null;
public void doPost(HttpServletRequest request,HttpServletResponse response) throws 

ServletException,IOException
{
Seatno=request.getParameter("Seatno");
Name=request.getParameter("Name");
ans1=request.getParameter("group1");
ans2=request.getParameter("group2");
ans3=request.getParameter("group3");
ans4=request.getParameter("group4");
ans5=request.getParameter("group5");
Total=0;
if(ans1.equals("True"))   Total+=2;
if(ans2.equals("True"))   Total+=2;
if(ans3.equals("True"))   Total+=2;
if(ans4.equals("True"))   Total+=2;
if(ans5.equals("False"))  Total+=2;
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("</head>");
out.println("<body bgcolor=pink>");
out.println("Hello       "+Name);
out.println("<br><br><br>");
out.println("Your seat no is     "+Seatno);
out.println("<br><br><br>");
out.println("Your final score is    "+Total);
out.println("<br><br><br>");
out.println("<center>");
out.println("<h1>Thanks!</h1>\n");
out.println("</center>");
out.println("</body></html>");
}}
                                        

XML DOCUMENT:

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" 

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

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <servlet>
        <servlet-name>student</servlet-name>
        <servlet-class>student</servlet-class>
        <init-param>
            <param-name>Seatno</param-name>
            <param-value/>
            <param-name>Name</param-name>
            <param-value/>
            </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>student</servlet-name>
        <url-pattern>/student</url-pattern>
    </servlet-mapping>
      <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
    <welcome-file>
            on.html
        </welcome-file>
    </welcome-file-list>
</web-app>


                                        
HTML CODE:
<html>
<head><title>Online Examination </title></head>
<body>
<center>
<h1>online exam</h1>
</center>
<form action="http://localhost:8080/student" method=POST>
<div align="left"><br>
<b>Seat Number:</b><input type="text" name="Seatno">
<div align=Right">
<b>Name:</b><input type="text" name="Name" size="30"><br>
</div>
<br><br>
<b>1.There are 7 layers in TCP/IP Protocol</b><br>
<input type="radio" name="group1"value="True">True
<input type="radio" name="group1"value="False">False<br><br>

<b>2.CDMA stands for Collision Detection Multiple Access</b><br>
<input type="radio" name="group2"value="True">True
<input type="radio" name="group2"value="False">False<br><br>

<b>3.Every Host implements Transport layer</b><br>
<input type="radio" name="group3"value="True">True
<input type="radio" name="group3"value="False">False<br><br>

<b>4.Packet switching is more useful in bursty traffic</b><br>
<input type="radio" name="group4"value="True">True
<input type="radio" name="group4"value="False">False<br><br>

<b>5.HTML is a protocol for describing web contents</b><br>
<input type="radio" name="group5"value="True">True
<input type="radio" name="group5"value="False">False<br><br>

<br><br><br>
<center>
<input type="submit" value="Submit"><br>
</center>
</form>
</body>
</html>


      Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/