Sie sind auf Seite 1von 75

LAYOUT

import java.applet.*; import java.awt.*; import java.awt.event.*; /*<applet code="layout.java" width=400 height=350> </applet>*/ public class layout extends Applet { Panel[] p1; Panel p2; static int border=0; static int card=1; static int flow=2; static int grid=3; static int gridBag=4; String[] l={"Border","Card","Flow","Grid","GridBag"}; String[] c={"First","Last","Next","Previous"}; Button[] lb=new Button[l.length]; Button[] nb=new Button[c.length]; Panel lbp=new Panel(); Panel nbp=new Panel(); public void init() { setLayout(new BorderLayout()); setupButtons(); add("North",lbp); setupDisplayPanels(); } void setupButtons() { for(int i=0;i<l.length;++i) { lb[i]=new Button(l[i]); lb[i].addActionListener(new ButtonHandler()); lbp.add(lb[i]); } for(int i=0;i<c.length;++i) { nb[i]=new Button(c[i]); nb[i].addActionListener(new ButtonHandler()); nbp.add(nb[i]); } } void setupDisplayPanels()

{ p1=new Panel[5]; for(int i=0;i<5;++i) p1[i]=new Panel(); p1[border].setLayout(new BorderLayout()); p1[card].setLayout(new CardLayout()); p1[flow].setLayout(new FlowLayout()); p1[grid].setLayout(new GridLayout(2,3)); GridBagLayout gbl=new GridBagLayout(); p1[gridBag].setLayout(gbl); p1[border].add("North",new Button("North")); p1[border].add("South",new Button("South")); p1[border].add("East",new Button("East")); p1[border].add("West",new Button("West")); p1[border].add("Center",new Button("Center")); String cb[]={"First","Second","Third","Fourth","Last" }; String fb[]={"One","Two","Three","Four","Five"}; String gb[]={"(0,0)","(1,0)","(2,0)","(0,1)","(1,1)","(2,1)"}; for(int i=0;i<cb.length;++i) p1[card].add("next card",new Button(cb[i])); for(int i=0;i<fb.length;++i) p1[flow].add(new Button(fb[i])); for(int i=0;i<gb.length;++i) p1[grid].add(new Button(gb[i])); Button gbb[]=new Button[9]; for(int i=0;i<9;++i) gbb[i]=new Button("Button"+i); int gridx[]={0,1,2,0,2,0,1,1,0}; int gridy[]={0,0,0,1,1,2,2,3,4}; int gridwidth[]={1,1,1,2,1,1,1,2,3}; int gridheight[]={1,1,1,1,2,2,1,1,1}; GridBagConstraints gbc[]=new GridBagConstraints[9]; for(int i=0;i<9;++i) { gbc[i]=new GridBagConstraints(); gbc[i].fill=GridBagConstraints.BOTH; gbc[i].gridx=gridx[i]; gbc[i].gridy=gridy[i]; gbc[i].gridwidth=gridwidth[i]; gbc[i].gridheight=gridheight[i]; gbl.setConstraints(gbb[i],gbc[i]); p1[gridBag].add(gbb[i]); } add("Center",p1[border]); p2=p1[border]; }

void switchPanels(Panel newPanel,boolean setNavigateButtons) { remove(p2); p2=newPanel; add("Center",p2); remove(nbp); if(setNavigateButtons) add("South",nbp); validate(); } class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent ev) { String s=ev.getActionCommand(); if(s.equals("Border")) switchPanels(p1[border],false); else if(s.equals("Card")) switchPanels(p1[card],true); else if(s.equals("Flow")) switchPanels(p1[flow],false); else if(s.equals("Grid")) switchPanels(p1[grid],false); else if(s.equals("GridBag")) switchPanels(p1[gridBag],false); else if(s.equals("First")) { CardLayout cl=(CardLayout)p2.getLayout(); cl.first(p2); } else if(s.equals("Last")) { CardLayout cl=(CardLayout)p2.getLayout(); cl.last(p2); } else if(s.equals("Next")) { CardLayout cl=(CardLayout)p2.getLayout(); cl.next(p2); } else if(s.equals("Previous")) { CardLayout cl=(CardLayout)p2.getLayout(); cl.previous(p2); }}}}

OUTPUT:

AWT CONTROLS

import java.awt.*; import java.awt.event.*; import java.applet.*; /*<applet code="awt.java" height=1000 width=1000> </applet>*/ public class awt extends Applet implements ActionListener,ItemListener,TextListener { Label l1,l2,l3,l4,l5,l6; Checkbox c1,c2,c3; TextField t1; List li1,li2,li3; Choice c; Button b1,b2; TextArea t; public void init() { setLayout(null); l1=new Label("CUSTOMER NAME:"); l1.setBounds(100,20,100,20); add(l1); t1=new TextField(60); t1.setBounds(300,20,200,20);

t1.addTextListener(this); add(t1); l2=new Label("TYPES OF BOOKS:"); l2.setBounds(100,80,120,20); add(l2); c1=new Checkbox("NOVEL"); c1.setBounds(300,70,140,20); c1.addItemListener(this); add(c1); c2=new Checkbox("MAGAZINES"); c2.setBounds(300,100,140,20); c2.addItemListener(this); add(c2); c3=new Checkbox("SOFTWARE BOOKS"); c3.setBounds(500,70,140,26); c3.addItemListener(this); add(c3); l3=new Label("NOVEL"); l3.setBounds(200,140,100,20); li1=new List(); li1.add("Oliver Twist"); li1.add("Harry Porter"); li1.add("Raja deysingh"); li1.setBounds(200,170,150,60); li1.addItemListener(this);

l4=new Label("MAGAZINES"); l4.setBounds(400,140,100,20); li2=new List(); li2.add("india today"); li2.add("Success competition"); li2.add("competition refreshers"); li2.setBounds(400,170,150,60); li2.addItemListener(this); l6=new Label("SOFTWARE BOOKS"); l6.setBounds(600,140,100,20); li3=new List(); li3.add("JAVA"); li3.add("C"); li3.add("C++"); li3.setBounds(600,170,100,50); li3.addItemListener(this); l5=new Label("DURATION"); l5.setBounds(100,240,150,20); add(l5); c=new Choice(); c.add("1 Week"); c.add("3 Week"); c.add("Month"); c.setBounds(300,240,100,20); c.addItemListener(this);

add(c); b1=new Button("SUBMIT"); b1.addActionListener(this); b1.setBounds(300,300,100,20); add(b1); b2=new Button("RESET"); b2.addActionListener(this); b2.setBounds(400,330,100,20); add(b2); t=new TextArea(); t.setBounds(200,330,300,100); t.addTextListener(this); add(t); } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==b1) { String s="CUSTOMER NAME:"; s+=t1.getText(); s+="\n"; s+="TYPE OF BOOKS:"; s+="\n\t"; s+=li1.getSelectedItem(); s+="\n\t";

s+=li2.getSelectedItem(); s+="\n\t"; s+=li3.getSelectedItem(); s+="\nDURATION:"; s+=c.getSelectedItem(); t.setText(s); } if(ae.getSource()==b2) { t1.setText(null); li1.setVisible(false); li2.setVisible(false); li3.setVisible(false); t.setText(null); if(c1.getState()==true) { c1.setState(false); } if(c2.getState()==true); { c2.setState(false); } if(c3.getState()==true) { c3.setState(false);

} } } public void textValueChanged(TextEvent te) {} public void itemStateChanged(ItemEvent ie) { if(ie.getSource()==c1) { if(c1.getState()==true) { add(l3); l3.setVisible(true); add(li1); li1.setVisible(true); } else { l3.setVisible(false); li1.setVisible(false); } } if(ie.getSource()==c2) { if(c1.getState()==true)

{ add(l4); l4.setVisible(true); add(li2); li2.setVisible(true); } else { l4.setVisible(false); li2.setVisible(false); } } if(ie.getSource()==c3) { if(c3.getState()==true) { add(l6); l6.setVisible(true); add(li3); li3.setVisible(true); } else { l6.setVisible(false); li3.setVisible(false);

} } } }

OUTPUT:

CHAT APPLICATION

CHAT CLIENT:
import java.awt.*; import java.applet.*; import java.awt.event.*; import java.net.*; import java.io.*; /*<applet code="chatclient.class"width=350 height=400></applet>*/ public class chatclient extends Applet implements ActionListener,KeyListener,Runnable { String buffer,clear,str; TextArea text1,text2; Button send,exit; byte ns[]; byte bs[]; byte br[]; int key,input; DatagramSocket clientSocket1=null; DatagramSocket clientSocket2=null; DatagramPacket dpr; DatagramPacket dps; Thread t; public void init() { setLayout(null); text1=new TextArea(buffer,10,40); text2=new TextArea(buffer,5,40);

send=new Button("send"); exit=new Button("exit"); text1.setBounds(5,5,300,300); text2.setBounds(5,310,300,150); send.setBounds(310,310,50,50); exit.setBounds(310,370,50,50); exit.addActionListener(this); send.addActionListener(this); text1.addKeyListener(this); text2.addKeyListener(this); add(text1); add(text2); add(send); add(exit); try { clientSocket1=new DatagramSocket(); } catch(Exception e) {} } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==send) { t.suspend(); buffer=text2.getText();

text2.setText(clear); text1.append("\n client:"+buffer); try { bs=new byte[250]; bs=buffer.getBytes(); dps=new DatagramPacket(bs,bs.length,InetAddress.getLocalHost(),2000); clientSocket1.send(dps); } catch(Exception ex) {} t.resume(); } if(ae.getSource()==exit) { System.exit(0); }} public void keyPressed(KeyEvent ke) { key=ke.getKeyCode(); if(key==KeyEvent.VK_ENTER) { t.suspend(); buffer=text2.getText(); text2.setText(clear); text1.append("\n client:"+buffer); try

{ bs=new byte[250]; bs=buffer.getBytes(); dps=new DatagramPacket(bs,bs.length,InetAddress.getLocalHost(),2200); clientSocket1.send(dps); } catch(Exception ex) {} t.resume(); }} public void keyReleased(KeyEvent ke) { showStatus("the user is idle"); } public void keyTyped(KeyEvent ke) { showStatus("the user is typing"); } public void start() { t=new Thread(this); t.start(); } public void run() { try {

System.out.println("thread"); while(true) { br=new byte[300]; dpr=new DatagramPacket(br,br.length); clientSocket1.receive(dpr); str=new String(br); text1.append("\n server:"+str); System.out.println("thread received"); } } catch(Exception e) {} } }

CHAT SERVER:
import java.awt.*; import java.applet.*; import java.awt.event.*; import java.net.*; import java.io.*; /*<applet code="chatserver.class"width=350 height=400></applet>*/ public class chatserver extends Applet implements ActionListener,KeyListener,Runnable { String buffer,clear,str; TextArea text1,text2; Button send,exit;

byte bs[]; byte br[]; int key,input;

DatagramSocket clientSocket2=null; DatagramPacket dpr; DatagramPacket dps; Thread t; int port; public void init() { setLayout(null);

text1=new TextArea(buffer,10,40); text2=new TextArea(buffer,5,40); send=new Button("send"); exit=new Button("exit"); text1.setBounds(5,5,300,300); text2.setBounds(5,310,300,150); send.setBounds(310,310,50,50); exit.setBounds(310,370,50,50); exit.addActionListener(this); send.addActionListener(this); text1.addKeyListener(this); text2.addKeyListener(this); add(text1); add(text2); add(send); add(exit); try { clientSocket2=new DatagramSocket(2000); } catch(Exception e) {} } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==send) {

t.suspend(); buffer=text2.getText(); text2.setText(clear); text1.append("\n server:"+buffer); try { bs=new byte[250]; bs=buffer.getBytes(); dps=new DatagramPacket(bs,bs.length,InetAddress.getLocalHost(),port); clientSocket2.send(dps); } catch(Exception ex) {} t.resume(); } if(ae.getSource()==exit) { System.exit(0); }} public void keyPressed(KeyEvent ke) { key=ke.getKeyCode(); if(key==KeyEvent.VK_ENTER) { t.suspend(); buffer=text2.getText(); text2.setText(clear);

text1.append("\n server:"+buffer); try { bs=new byte[250]; bs=buffer.getBytes(); dps=new DatagramPacket(bs,bs.length,InetAddress.getLocalHost(),port); clientSocket2.send(dps); } catch(Exception ex) {} t.resume(); }} public void keyReleased(KeyEvent ke) { showStatus("the user is idle"); } public void keyTyped(KeyEvent ke) { showStatus("the user is typing"); } public void start() { t=new Thread(this); t.start(); } public void run() {

try { while(true) { br=new byte[300]; dpr=new DatagramPacket(br,br.length); clientSocket2.receive(dpr); port=dpr.getPort(); str=new String(br); text1.append("\n server:"+str); } } catch(Exception e) {} } public void stop() { try { clientSocket2.close(); } catch(Exception ex) {} } }

OUTPUT:

APPLETS-COLOR PALETTE
import java.awt.*; import java.awt.event.*; import java.applet.*; /*<applet code="color2.java" width=300 height=300> </applet>*/

public class color2 extends Applet implements ItemListener { int currcolor=5; int flag=1; String text="Click any of the 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(int 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(),"Sunset.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.white); 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:

WEBPAGE CREATION
COLLEGE WEBSITE COLLEGE.HTML
<html> <head> <title><college></title> </head> <body> <H1 ALIGN="center">AARUPADAI VEEDU INSTITUTE OF TECHNOLOGY</H1> <body bgcolor="f0f0f0"text="ff0ee8"> <hr> <a href="Information.html">about</a> <a href="Sports.html">sports</a> <a href="Academic.html">academic</a> <a href="Hostel.html">hostel</a> </body> </html>

INFORMATION.HTML
<html> <head> <title>about</title> </head>

<body> <body bgcolor="555566"text="aabbcc"> <FONT COLOR="PINK"> <H2 align="center">ABOUT OUR COLLEGE</H2> <hr> </FONT> <U><DIV ALIGN="CENTER"><P TITLE="INTRODUCTORY PARAGRAPH"> Aarupadai Veedu Institute Of Technology Engg. College</U>was started at the year <tt>2001</tt> At first it was started with only<cite>three</cite>Deaprtments.</P> <p>Because of its good administration one more department be included within next year itself. Now it has four departments.</P></DIV> <UL TYPE=ROUND> <DIV ALIGN="LEFT"> <KBD>FOUR DEPARTMENTS ARE:</KBD> </DIV><EM> <UL> <LI>CSE DEPARTMENT <LI>ECE DEPARTMENT <LI>EEE DEPARTMENT <LI>IT DEPARTMENT </UL> </UL> </body> </html>

ACADEMIC.HTML
<html>

<head> <title>academic</title> </head> <body> <BODY BGCOLOR="aa0870"TEXT="aaabbb"> <H2 ALIGN ="CENTER">ACADEMIC COURCES</H2> <hr><br><br> Courses available in our college are: </ul types=disc> <li><I>Computer Science & Engineering</I> <li><I>Electronic & Communication Engineering</I> <li><I>Electrical & Electronics Engineering</I> <li><I>Information & Technology</I> </body> </html>

SPORTS.HTML
<html> <head> <title>sports</title> </head> <body> <body bgcolor="555566"text="ffbb55"> <H2 ALIGN="CENTER">SPORTS</H2> <hr> <p> <abbr>AVITEC</abbr>has several facilities for sports.

They try to involve their students to participate in the inter_college competitions. <p> NCC & NSS camps are also available. In college campus itself they are allowing to practising all <tt>indoor & outdoor</tt>games. </body> </html>

HOSTEL.HTML

<html> <head> <title>hostel</title> </head> <body> <body text="ddddbb"bgcolor="555566"> <H2 ALIGN="CENTER">HOSTEL FACILITIES</H2> <HR> <center> <marquee direct="down"scrollamount="2"> <p>The college hostel is separated into <I>Girl's Hostel</I>and<I>Boy's Hostel.</I> </p></marquee> <p>Girl's Hostel is situated at <tt>Paiyanoor<tt>near<B>Mahabalipuram</B> It is a Working Women's Hostel.Many Facilities are available. A swimming pool is also available. Facilities like:</center> <blockquote>

Browsing center,Bus facility,Medical Camp,Coaching center,etc. </blockquote> </p> <p> Boy's Hostel is situated in the college campus itself. Here also lots of facilities are available. </p> </body> </html>

OUTPUT:

WEBPAGE CREATION
IMAGE MAP

IMAGE.HTML:<html> <head> <title>iimage</title> </head> <body background="imagemap.bmp"><H1 align="center">INDIA MAP</H1> <pre> delhi <a href="delhi.html"><img src="D:\image\Indiamap.bmp"></a> kolkata <a href="kolkata.html"><img src="D:\image\Indiamap.bmp"></a> mumbai

<a href="mumbai.html"><img src="D:\image\Indiamap.bmp"></a> chennai <a href="chennai.html"><img src="D:\image\Indiamap.bmp"></a> </pre> </body> </html>

DELHI.HTML
<html> <head> <title>delhi</title> </head> <body BGCOLOR="000000"TEXT="aa1123"> <H1 align="center",>DELHI</H1> <HR> <pre> <p> In Delhi lots of place is there to visit. Most of the places are so attractive. </p> <p>Once we visit the place, we wish to visit it aagain there every summer holidays.</p> <p>One of the place is <tt> Taj Mahal</tt.. It is situated near Agra.</p> <ul><li>It is one of the "WONDERS OF THE WORLD".</ul></pre> <hr> </body> </html>

KOLKATTA.HTML

<html> <head> <title>kolkata</title> </head> <body BGCOLOR="556566"TEXT="AAfffC"> <H1 align="center",>KOLKATA</H1> <HR> <p>Kolkata is the capital of<West Bengal</i> <p>Mother tongue"Bengali". <p>the famous cricket player resides in this city. <p>Before it was called"Calcutta" </body> </html>

MUMBAI.HTML
<html> <head> <title>mumbai</title> </head> <body BGCOLOR="555566"TEXT="AABBCC"> <H1 align="center",>MUMBAI</H1> <HR> Mumbai is the place for harbours. This is the second India gate of India. Here also a lot of place is there for visit. <p> Many tourists come to this place.

Mumbai is one of thedevelopd city in India. </p> <hr> </body> </html>

CHENNAI.HTML
<html> <head> <title>chennai</title> </head> <body BGCOLOR="000000"TEXT="ff88CC"> <H1 align="center",>CHENNAI</H1> <HR> Chennai is the busiest city. Here lots of shopping complex are available. EEveryday there be a lots of people come for Shopping. Moreover employment is large in chennai. Nowadays the eeeflat systems are improved in Chennai. Here also lot of place for visiting. for.eg. </ul> </li>Museum, <li>marina beach, <li>basin nagar beach,etc., <hr> </body>

</html>

OUTPUT:

CASCADING STYLE SHEETS


EARTHQUAKE.HTML
<html> <head> <title>earthquake</title> <LINK REL="STYLESHEET"TYPE="TEXT/CSS"HREF="a.css"></LINK> </head> <body> <hr> <H1>EARTHQUAKE-EXTERNAL</H1> <hr> <p id=one> The earthquake occurs due to the rubbing of one rock over the another rock. The earthquake is off different speed, direction, strength,etc. </p> <p>It consists of several layers and each layer moves in different way. <ul> <li>Primary layer flows in length wise. <li>Secondary layer flows cross wise. <li>Next layer flows around that particular area. </ul> </p> <p id=two> This can be measured using ritcher scale. Actually in that instrument a chart be present.

This instrument be<i>fixed rigidly</i>on the ground and so whenever the earthquake occurs it never distracted and measure accurately. </p> <hr> </body> </html>

A.CSS
body { background:000000; font size:14; color:999000; } H1 { text-align:center; color:555566; } #one { color:ff00ff; font size: 15; } #two { font size: 11; color:0088ff;

} ul { font size:13; font-family:Comic Sans MS; } i { color:ff00ff; }

EARTHQUAKE1.HTML:<html> <head> <title>Eartquake1</title> <style type="text/css"> body { background:green; font-size:18; color:black; } H1 { text-align:center; color:555566; }

#one { color:ff00ff; font-size:15; } #two { font-size:11; color:0088ff; } ul { font size 13; font-family: Comic Sans MS; } i { color:ff00ff; } </style> </head> <body> <hr> <p id=one> The earthquake occurs due to the rubbibng of one rock over the onother rock. The earthquake is off different sprrd, direction,strength,etc;

</p> <p> It consist of several layers and each layer moves in differnet way. <ul> <li>Primary layer flows in length wise. <li>Secondary layer flows across wise. <li>Next layer flows around that particular area. </ul> </p> <p id=two> This can be measured using ritcher scale. Actually in that instrument a chart be present. This instrument be <I>fixed rigidly</i>on the ground and so whenever the earthquake occurs it never distracted and measure accirately. </p> <hr> </body> </html>

EARTHQUAKE2.HTML:<html> <head> <title>earthquake</title> </head> <body style="background: 555566;font size:20;color:999000"> <hr> <H1 style="text-align:center; color:990066">EARTHQUAKE-INLINE</H1> <hr>

<p style="color:ff00ff;font size=15;"> The earthquake occurs due to the rubbing of one rock over the another rock. The earthquake is off different speed, direction, strength,etc. </p> <p style="font size:11;color:0088ff;"> <p>It consists of several layers and each layer moves in different way. <ul style="font size:13;font-family:comissans MS;"> <li>Primary layer flows in length wise. <li>Secondary layer flows cross wise. <li>Next layer flows around that particular area. </ul> </p> <p id=two> This can be measured using ritcher scale. Actually in that instrument a chart be present. This instrument be<i>fixed rigidly</i>on the ground and so whenever the earthquake occurs it never distracted and measure accurately. </p> <hr> </body></html>

OUTPUT:

WEBPAGE CONTENT RETRIVAL USING URL

Program:-

import java.net.*; import java.io.*; import java.util.Date; class url { public static void main(String args[])throws Exception { int ch; URL handle=new URL("http://www.google.com"); URLConnection handle_connection=handle.openConnection();

long date_info; int length,i; date_info=handle_connection.getDate(); System.out.println("Date:"+new Date(date_info)); System.out.println("Content-Type:"+handle_connection.getContentType()); length=handle_connection.getContentLength(); System.out.println("Content length:"+length); if(length!=0) { System.out.println("\n\t*** Contents of web page are ****"); InputStream input_string=handle_connection.getInputStream(); while((ch=input_string.read())!=-1) { System.out.println((char)ch); } input_string.close(); } else { System.out.println("There are no Content for this site"); } } }

OUTPUT:
Date:Thu Jan 01 00:00:00 GMT+05:30 1970 Content-Type:null Content length:-1

*** Contents of web page are **** java.net.UnknownHostException: www.google.com

at java.net.InetAddress.getAllByName0(InetAddress.java:479) at java.net.InetAddress.getByName(InetAddress.java:355) at java.net.Socket.<init>(Socket.java:97) at sun.net.NetworkClient.doConnect(NetworkClient.java:62) at sun.net.www.http.HttpClient.openServer(HttpClient.java:267) at sun.net.www.http.HttpClient.openServer(HttpClient.java:329) at sun.net.www.http.HttpClient.<init>(HttpClient.java:210) at sun.net.www.http.HttpClient.<init>(HttpClient.java:218) at sun.net.www.http.HttpClient.New(HttpClient.java:229) at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection .java:235) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon nection.java:315) at Get_Web_Page.main(Get_Web_Page.java:21)

C:\JDK11~1.3\bin>

SOCKETS- HTTP REQUEST


import java.io.*; import java.net.*; public class HTTP_Request { public static void main(String args[]) throws Exception { try { String Request="www.google.com"; Socket client_Socket=new Socket(Request,80); System.out.println("The client is \n"+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());

}}}

OUTPUT:
The client is Socket[addr=www.google.com/209.85.231.104,port=80,localport=3788] HTTP/1.0 400 Bad Request Content-Type: text/html; charset=UTF-8 Content-Length: 1350 Date: Fri, 01 Oct 2010 13:30:25 GMT Server: GFE/2.0

<html><head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <title>400 Bad Request</title> <style><!-body {font-family: arial,sans-serif} div.nav {margin-top: 1ex} div.nav A {font-size: 10pt; font-family: arial,sans-serif} span.nav {font-size: 10pt; font-family: arial,sans-serif; font-weight: bold} div.nav A,span.big {font-size: 12pt; color: #0000cc} div.nav A {font-size: 10pt; color: black} A.l:link {color: #6f6f6f} A.u:link {color: green} //--></style> <script><!--

var rc=400; //--> </script> </head> <body text=#000000 bgcolor=#ffffff> <table border=0 cellpadding=2 cellspacing=0 width=100%><tr><td rowspan=3 width=1 % nowrap> <b><font face=times color=#0039b6 size=10>G</font><font face=times color=#c41200 size=10>o</font><font face=times color=#f3c518 size=10>o</font><font face=times color=#0039b6 size=10>g</font><font face=times color=#30a72f size=10>l</font><f ont face=times color=#c41200 size=10>e</font>&nbsp;&nbsp;</b> <td>&nbsp;</td></tr> <tr><td bgcolor="#3366cc"><font face=arial,sans-serif color="#ffffff"><b>Error</ b></td></tr> <tr><td>&nbsp;</td></tr></table> <blockquote> <H1>Bad Request</H1> Your client has issued a malformed or illegal request.

<p> </blockquote> <table width=100% cellpadding=0 cellspacing=0><tr><td bgcolor="#3366cc"><img alt ="" width=1 height=4></td></tr></table> </body></html>

STUDENT MARK LIST

/*student.java*/ import java.servlet.*; import javax.servlet.http.*; import java.io.*; import java.sql.*;

public class student extends HttpServlet { int m1,m2,m3.n1; String s1; Connection cn; Statement st; public void init(ServletConfig c)throws ServletException { try

{ Class.forName("sun.jdbc.odbcDriver"); st=cn.createStatement(); System.out.println("try"); } catch(Exception e) { System.out.println("e"); } public void doGet(HttpServletRequest req,HttpServletResponse rs)tthrows ServletException,IOException { try { res.setContentType("text/html"); PrintWriter out=res.getWriter(); String e=req.getParameter("t1"); int i=Integer.println(e); System.out.println("s"); ResultSet re=st.executeQuery("select*from std where id="+i+""); while(re.next(()); { s1=re.getString(1); n1=re.getInt(2); m1=re.getInt(3); m2=re.getInt(4);

m3=re.getInt(5); } out.println("<html><head><title>Student marklist</title></head>"); out.println("<body bgcolor=556655 text=ccffcc>"); out.println("<center><h1>STUDENT MARKSHEET</h1></center>"); System.out.println("hjhfdhfds"); out.println("<center><pre><br><h2>"); out.println("NAME:"+S1); out.println("reg no:"+n1); out.println("maths:"+m2); out.println("chemistry:"+m3); out.println("</h2>"); out.println("</pre>"); out.println("<center>"); out.println("</body></html>"); } catch(Exception e) { System.out.println(e); } } }

/* student.html*/

<html> <head> <title>stud</title></head> <body bgcolor="556655"text="ccffcc"> <h1><center>STUDENT MARKLIST</center></h1> <form method=get action="http:\\LocalHost:8080\servelet\dtudent"> <center> ID<input type=text name=t1 size=10></h2> <input type=submit name=t2 size=10></h2> </center> </form> </body> </html>

OUTPUT:

ONLINE EXAMINATION
/*online.java*/

import javax.servlet.http.*; import java.io.*; import java.awt.*; import java.awt.event.*; import java.sql.*; public class online extends HttpServlet { int total;

Connection cn; Statement st; public oid init(ServerConfig c)throws ServletException { try { Class.forName("sun.jdbc.odbc.JdbcOdbc:dbonline"); cn=DriverManager.getConnection("jdbc:odbc:dbonline") st=cn.createStatement(); System.out.println("try"); } catch(exception e) { System.out.println("e"); } } public void doGet(HttpServletRequest reg,HttpServerResponse res)throws ServerException,IOException { res.setContentType("text/html"); PrintWriter out=res.getWriter(); String ans[]=new String[4]; String answer[]=new String[4]; ans[0]=req.getParameter("q1"); ans[1]=req.getParameter("q2"); ans[2]=req.getParameter("q3");

int n=0; try { ResultSet re=st.executeQuery("select * from questions"); n=0; while(re.next()) { answer[n]=re.getString(2); n++; } } catch(Exception e) { } total=0; for(int i=0;i<3;i++) { if(answer[i].equals(ans[i])) total=total+10; } out.println("<html><head><title>REsults</title></head>"); out.println("<body bgcolor=556655 text=ff0000>"); out.println("<br><br><br>"); out.println(<center><h3>THANKYOU,YOU HAVE SCORED"+total+"</h3></center>"); int e=1; for(int i=0;i<3;i++) {

if(answer[i].equals(ans[i])) out.println(""+e+">correct<br><br>"); else { out.println(""+e+">Wronganswer<br>"); out.println(<br>The correct answer is:"+answer[i]+"<br><br>"); } e++; } System.out.println("hjhfdhfds"); out.println("</body></html>"); } }

/* online.html*/ <html> <head> <title>online</title> </head> <body bgcolor="aabbcc"text="00ff44"> <form name=f1 method=get action="http:\\localhost:8080\servlet\online"> <center><h3>ONLINE EXAMINATION</h3></center> <center><table border=0> <tr> <td width=600> I>Feature not supported by java

</td> <br> <td> <input type=radio name=q1 value="pointer">pointer &nbsp <input type=radio name=q1 value="inheritance">inheritance &nbsp <input type=radio name=q1 value="objects">objects &nbsp </td></tr> <tr> <td> 2>platform Independent language </td> <td> <input type=radio name=q2 value="java">java &nbsp <input type=radio name=q2 value="c">c &nbsp <input type=radio name=q3 value="c++">c++ &nbsp </td></tr> <tr> <td> 3>Automated object desructors in java </td> <td> <input type=radio name=q3 value="destructor">destructor &nbsp <input type=radio name=q3 value="constructor">constructor &nbsp <input type=radio name=q3 value="Garbage collector">Garbage collector &nbsp </td></ty> </table>

<input type=submit name=sub value="SUBMIT"> <input type=reset name=res value="RESET"> </center><form></body> </html>

OUTPUT:

Das könnte Ihnen auch gefallen