TABLE OF CONTENTS EXPT PAGE No DATE NAME OF THE EXPERIMENT NO SIGN 1 AWT COMPONENTS 2(a) FLOW LAYOUT 2(b) BORDER LAYOUT 2(c) GRID LAYOUT 2(d) CARD LAYOUT 3 COLOR PALETTE 4(a) DOWNLOAD THE HOME PAGE OF THE SERVER 4(b ) DISPALAY THE CONTENTS OF THE HOME PAGE 5(a) HTTP REQUEST 5(b) FILE TRANSFER PROTOCOL 6 UDP CHAT
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
TABLE OF CONTENTSEXPT PAGE No DATE NAME OF THE EXPERIMENT NO SIGN
1 AWT COMPONENTS
2(a) FLOW LAYOUT 2(b) BORDER LAYOUT
2(c) GRID LAYOUT
2(d) CARD LAYOUT
3 COLOR PALETTE
4(a) DOWNLOAD THE HOME PAGE OF THE SERVER
4(b ) DISPALAY THE CONTENTS OF THE HOME PAGE
5(a) HTTP REQUEST
5(b) FILE TRANSFER PROTOCOL
6 UDP CHAT
7 INVOKING SERVLETS FROM HTML
8(a) ONLINE EXAMINTAION USING SERVLETS
8(b) STUDENT MARKLIST USING SERVLETS
9 CREATING AND USING IMAGE MAPS
10 STYLE SHEETS
EXPT NO: 01 AWT COMPONENTS
AIM:
To demonstrate the working of AWT components using java programming
ALGORITHM:
Step 1: Import the necessary java classes lile awt,event that handle awt components
Step 2: In Applet classimplement the interfaces like ActionListener,ItemListener etc,
that handles interactions of the components.
Step 3: Create components like TextField,Buttons,Lists,Choices with appropriate
syntaxes
Step 4: Add all the components that was created in init()
Step 5: Specify the current object for all components in init()
Step 6: Inside the methods of interfaces( like actionPerformed..) check for the status of
Thus the program is executed successfully and verified.
EXPT NO: 02(B) BORDER LAYOUT
AIM:
To demonstrate the Border Layout using java program.
ALGORITHM:
Step 1: Import all necessary packages and classes.
Step 2: Define a class that extends Applet.
Step 3: Create a Border layout.
Step 4: Set the layout using its instance.
Step 5: Create Buttons, TextFields and add it in the border layout with specific
direction in the init function.
PROGRAM:
import java.awt.*;import java.applet.*;import java.util.*;/*<applet code="borderlayout" width=400 height=400></applet>*/public class borderlayout extends Applet{ public void init(){setLayout(new BorderLayout());add(new Button("RAJA RAJESWARI Engineering College"),BorderLayout.NORTH);add(new Label("A.C.S GROUP OF COLLEGES"),BorderLayout.SOUTH);add(new Button("Mission"), BorderLayout.EAST); add(new Button("Vision"), BorderLayout.WEST);String msg="Raja Rajeswari Engineering College was established \n" +"in the year 1997 under the A.C.S Group of Colleges\n"+"whose members have had consummate experience in the fields of \n" +"education and industry."; add(new TextArea(msg),BorderLayout.CENTER);}}
Thus the program is executed successfully and verified.
EXPT NO: 03 COLOR PALETTE
AIM:
To write a java program to create applets with the following features
Create a color palette with matrix of buttons.
a. Set background and foreground of the control text area by selecting a color
from color palette.
b. In order to select foreground or background use checkbox controls as
radio buttons.
c. To set background images.
ALGORITHM:
Step 1: Import all necessary packages and classesStep 2: Define a class that extends applet and implements action listener and item
listenerStep 3: Declare an array of buttons to set colors, two checkboxes for foreground and background colorsStep 4: Declare a text area to hold the text, a checkbox group for checkboxesStep 5: Add the array of buttons in the init function.Step 6: In the actionPerformed() method, do the following: i) Get the action command in the string, color ii) If foreground is checked then set the foreground color to the selected color
iii) If background is checked then set the background color to the selected color
PROGRAM:
import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="exp" width=400 height=400></applet>*/public class exp extends Applet implements ItemListener{int currcolor=5;int flag=1;String text="Click any of the buttons";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)
Thus the program is executed successfully and verified.
EXPT NO: 04(A) DOWNLOAD THE HOME PAGE OF THE SERVER
AIM:
To write a java program to download a page from a web site
ALGORITHM:
Step 1: Create a URL to any web site and open a URL Connection using
OpenConnection ().
Step 2: Download the web page from the server
Step 3: Open an input stream with the URL Connection
Step 4: If url is incorrect display “ url is not parseable “
PROGRAM:
import java.net.*;import java.io.*;public class mime1{public static void main (String[] args){ if (args.length >0){try{URL u = new URL(args[0]);InputStream in = u.openStream( );in = new BufferedInputStream(in);Reader r = new InputStreamReader(in);int c;while ((c = r.read( )) != -1){System.out.print((char) c);} } catch (MalformedURLException ex){System.err.println(args[0]+" is not a parseable URL");} catch (IOException ex){System.err.println(ex);} }}}
OUTPUT:
RESULT:
Thus the program is executed successfully and verified.
EXPT NO: 04(B) DISPLAY THE CONTENTS OF THE HOME PAGE
AIM:
To write a java program to display the properties of the web page.
ALGOTITHM:
Step 1: Create a URL to any web site and open a URL Connection using
OpenConnection ().
Step 2: Get the date, content type, last modified and length of the page and
display them
Step 3: Open an input stream with the URL Connection
Step 4: If no content is available then display “no content is available"
PROGRAM:
import java.net.*;import java.io.*;import java.util.*;public class mime2{public static void main(String args[]){for(int i=0;i<args.length;i++){try{URL u=new URL(args[0]);URLConnection uc=u.openConnection();System.out.println("Content-Type:"+uc.getContentType());System.out.println("Content-Encoding:"+uc.getContentEncoding());System.out.println("Date:"+new Date(uc.getDate()));System.out.println("Last Modified:"+new Date(uc.getLastModified()));System.out.println("Expiration Date:"+new Date(uc.getExpiration()));System.out.println("Content-Length:"+uc.getContentLength());}catch(MalformedURLException e){System.err.println(args[i]+" is not a URL i understand");}catch(IOException e){System.err.println(e);}
System.out.println();}}}
OUTPUT:
RESULT: Thus the program is executed successfully and verified.
EXPT NO: 05(A) HTTP REQUEST
AIM:
To write a java socket program to demonstrate HTTP Request
ALGORITHM:
Step 1: Import all the necessary packagesStep 2: Create an URL to the server specifying the html page
Step 3: Get the host and port details from the URL
Step 4: Request the file from the server using GET method of HTTP Request
Step 5: Receive the response from the server
Step 6: Display the response on the console
PROGRAM:
import java.net.*;import java.io.*;import javax.swing.*;import java.awt.*;public class SourceViewer3 {public static void main (String[] args) {for (int i = 0; i < args.length; i++) {try {URL u = new URL(args[i]);HttpURLConnection uc = (HttpURLConnection) u.openConnection( );int code = uc.getResponseCode( );String response = uc.getResponseMessage( );System.out.println("HTTP/1.x " + code + " " + response);for (int j = 1; ; j++) {String header = uc.getHeaderField(j);String key = uc.getHeaderFieldKey(j);if (header == null || key == null) break;System.out.println(uc.getHeaderFieldKey(j) + ": " + header);}InputStream in = newBufferedInputStream(uc.getInputStream( ));Reader r = new InputStreamReader(in);int c;while ((c = r.read( )) != -1) {System.out.print((char) c);}}catch (MalformedURLException ex) {System.err.println(args[0] + " is not a parseable URL");}catch (IOException ex) {System.err.println(ex);}}}}
OUTPUT:
RESULT:
Thus the program is executed successfully and verified.
EXPT NO: 05(B) FILE TRANSFER PROTOCOL
AIM:
To write a java program to demonstrate a simple FTP operation
ALGORITHM:
FTP Client:
Step 1: Establish a connection with the server at a particular portStep 2: Specify the name of the file to be readStep 3: Receive the contents of the file from the server
FTP Server:
Step 1: Accept the connection with the clientStep 2: Listen to the port for the name of the file to be sentStep 3: Send the file character by characterStep 4: Terminate the connection
PROGRAM:
FileServer.java
import java.net.*;import java.io.*;public class FileServer{ServerSocket serverSocket;Socket socket;int port;FileServer(){this(9999);}FileServer(int port){this.port = port;}void waitForRequests() throws IOException{serverSocket = new ServerSocket(port);while (true){System.out.println("Server Waiting...");socket = serverSocket.accept();System.out.println("Request Received From " + socket.getInetAddress()+"@"+socket.getPort());new FileServant(socket).start();System.out.println("Service Thread Started");}}public static void main(String[] args){try{new FileServer().waitForRequests();}catch (IOException e){e.printStackTrace();}}}
FileClient.java
import java.net.*;import java.io.*;public class FileClient{String fileName;String serverAddress;int port;Socket socket;FileClient(){this("localhost", 9999, "Sample.txt");}FileClient(String serverAddress, int port, String fileName){this.serverAddress = serverAddress;this.port = port;this.fileName = fileName;}void sendRequestForFile() throws UnknownHostException,IOException{socket = new Socket(serverAddress, port);System.out.println("Connected to Server...");PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));writer.println(fileName);writer.flush();System.out.println("Request Sent...");getResponseFromServer();socket.close();}void getResponseFromServer() throws IOException{BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));String response = reader.readLine();if(response.trim().toLowerCase().equals("filenotfound")){System.out.println(response);return; }else{BufferedWriter fileWriter = newBufferedWriter(new FileWriter("Recdfile.txt"));
Thus the program is executed successfully and verified.
EXPT NO: 06 UDP CHAT
AIM:
To write a java program to create a simple chat application with datagram sockets and packets
ALGORITHM:
Server Side
Step 1: Import necessary packages.Step 2: Create a datagram socket and datagram packetStep 3: While client send datagram packet to server listen to client portStep 4: Get the datagram packet into a stringStep 5: Display the string
Client Side
Step 1: Import necessary packages Step 2: Create a datagram socket and datagram packetStep 3: Get input from the user and convert the string into a datagram packetStep 4: send the datagram packet to the server through serve port
PROGRAM:
UDPServer.java
import java.io.*;import java.net.*;class UDPServer{public static DatagramSocket serversocket;public static DatagramPacket dp;public static BufferedReader dis;public static InetAddress ia;public static byte buf[] = new byte[1024];public static int cport = 789,sport=790;public static void main(String[] a) throws IOException{serversocket = new DatagramSocket(sport);dp = new DatagramPacket(buf,buf.length);dis = new BufferedReader(new InputStreamReader(System.in));ia = InetAddress.getLocalHost();System.out.println("Server is Running...");while(true){serversocket.receive(dp);String str = new String(dp.getData(), 0,dp.getLength());if(str.equals("STOP")){System.out.println("Terminated...");break;}
import java.io.*;import java.net.*;class UDPClient{public static DatagramSocket clientsocket;public static DatagramPacket dp;public static BufferedReader dis;public static InetAddress ia;public static byte buf[] = new byte[1024];public static int cport = 789, sport = 790;public static void main(String[] a) throws IOException{clientsocket = new DatagramSocket(cport);dp = new DatagramPacket(buf, buf.length);dis = new BufferedReader(new InputStreamReader(System.in));ia = InetAddress.getLocalHost();System.out.println("Client is Running... Type 'STOP'to Quit");while(true){String str = new String(dis.readLine());buf = str.getBytes();if(str.equals("STOP")){System.out.println("Terminated...");clientsocket.send(new DatagramPacket(buf,str.length(), ia,sport));break;}clientsocket.send(new DatagramPacket(buf,str.length(), ia, sport));
clientsocket.receive(dp);String str2 = new String(dp.getData(), 0,dp.getLength());System.out.println("Server: " + str2);}}}
OUTPUT
RESULT:
Thus the program is executed successfully and verified.
EXPT NO: 07INVOKING SERVLETS FROM HTML
AIM:
To write html and servlet to demonstrate invoking a servlet from a html.
ALGORITHM:
Client:
Step1: In index.jsp on the client side declare the contents that you like to transfer to the server using html form and input type tags.Step2: create a submit button and close all the included tags.
Server:
Step1: In the servlet side using the parameter request get the stings declared in the client side (requst.getparameter)
Step2: Include necessary html coding that helps to display the content
<TITLE>INVOKING SERVLET FROM HTML</TITLE> </head><BODY><CENTER><FORM name = "PostParam" method = "Post" action="http://localhost:8080/servlets-examples/servlet/PostParam"><TABLE><tr><td><B>Employee </B> </td><td><input type = "textbox" name="ename" size="25"value=""></td></tr><tr><td><B>Phone </B> </td><td><input type = "textbox" name="phoneno" size="25"value=""></td></tr></TABLE><INPUT type = "submit" value="Submit"></FORM></CENTER></body></html>
OUTPUT:
RESULT:
Thus the program is executed successfully and verified.
EXPT NO: 08 (A) ONLINE EXAMINATION USING SERVLETS
AIM:
To write java servlet programs to conduct online examination and to display student mark list available in a database
ALGORITHM:
Client:
Step1: In index.html on the client side declare the contents that you like to transfer to the server using html form and input type tags.Step2: create a submit button and close all the included tags.
Servlet:
Step 1: Import all necessary packagesStep 2: Define a class that extends servlet
Step 3: In the doPost() method, do the following: i) Set the content type of the response to "text/html" ii) Create a writer to the response iii) Get a paratmeter from the request iv) If its value is equal to right answer then add 5 to mark variable v) Similarly repeat step vi) for all parameters vii) Display the result in an html format using the writer
STUDENT MARK LIST DATABASE
Step 1: Import necessary to java packages and javax packages and classesStep 2: Create a class that extends HttpServlet and implements ServletException and IOExceptionStep 3: In the doGet() method, do the following:
i) Create a PrintWriter object ii) Open a connection with the data source name iii) Write a sql query and execute to get the resultset iv) Display the resultset information in html form
PROGRAM:
SERVLET CODE:
import java.io.*;import java.sql.*;import javax.servlet.*;import javax.servlet.http.*;public class StudentServlet3 extends HttpServlet{String message,Seat_no,Name,ans1,ans2,ans3,ans4,ans5;int Total=0;Connection connect;Statement stmt=null;ResultSet rs=null;public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{try{String url="jdbc:odbc:NEO";Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");connect=DriverManager.getConnection(url," "," ");message="Thank you for participating in online Exam";}catch(ClassNotFoundException cnfex){cnfex.printStackTrace();}catch(SQLException sqlex){sqlex.printStackTrace();}catch(Exception excp){ excp.printStackTrace();}
Seat_no=request.getParameter("Seat_no");Name=request.getParameter("Name");ans1=request.getParameter("group1");ans2=request.getParameter("group2");ans3=request.getParameter("group3");ans4=request.getParameter("group4");ans5=request.getParameter("group5");if(ans1.equals("True"))Total+=2;if(ans2.equals("False"))Total+=2;if(ans3.equals("True"))Total+=2;if(ans4.equals("False"))Total+=2;if(ans5.equals("False"))Total+=2;try{Statement stmt=connect.createStatement();String query="INSERT INTO student("+"Seat_no,Name,Total"+") VALUES('"+Seat_no+"','"+Name+"','"+Total+"')";
int result=stmt.executeUpdate(query);stmt.close();}catch(SQLException ex){}response.setContentType("text/html");PrintWriter out=response.getWriter();out.println("<html>");out.println("<head>");out.println("</head>");out.println("<body bgcolor=cyan>");out.println("<center>");out.println("<h1>"+message+"</h1>\n");out.println("<h3>Yours results stored in our database</h3>");out.print("<br><br>");out.println("<b>"+"Participants and their Marks"+"</b>");out.println("<table border=5>");try{Statement stmt=connect.createStatement();String query="SELECT * FROM student";rs=stmt.executeQuery(query);out.println("<th>"+"Seat_no"+"</th>");out.println("<th>"+"Name"+"</th>");out.println("<th>"+"Marks"+"</th>");while(rs.next()){out.println("<tr>");out.print("<td>"+rs.getInt(1)+"</td>");out.print("<td>"+rs.getString(2)+"</td>");out.print("<td>"+rs.getString(3)+"</td>");out.println("</tr>");}out.println("</table>");}catch(SQLException ex){ }finally{try{if(rs!=null)rs.close();if(stmt!=null)stmt.close();if(connect!=null)connect.close();}catch(SQLException e){ }}out.println("</center>");out.println("</body></html>");Total=0;} }
<b>2. It is a network layer's responsibility to forward packets reliably from source to destination</b><br/><input type="radio" name="group2" value="True">True<input type="radio" name="group2" value="False">False<br>
<b>3. Packet switching is more useful in bursty traffic</b><br/><input type="radio" name="group3" value="True">True<input type="radio" name="group3" value="False">False<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>
Thus the program is executed successfully and verified.
EXPT NO: 8(B) STUDENT MARKLIST USING SERVLET
AIM:
To create a three tier application for displaying the student marklist
ALGORITHM:
Client:
Step1: In index.html on the client side declare the contents that you like to transfer to the server using html form and input type tags.Step2: create a submit button and close all the included tags.
Servlet:
Step 1: Import all necessary packagesStep 2: Define a class that extends servlet
Step 3: In the doPost() method, do the following: i) Set the content type of the response to "text/html" ii) connect with the database which has the student marklist iii) query the data to the database Step 4: Display the student marklist
String query=new String("SELECT * FROM MarkList WHERE regno= "+Reg_no);rs=stmt.executeQuery(query);boolean b=rs.next();out.println("Regsitration No:"+rs.getInt(1));out.println("<br>"+"Name:"+rs.getString(2));out.println("<table border=5>");out.println("<th>"+"cs01"+"</th>");out.println("<th>"+"cs02 "+"</th>");out.println("<th>"+"cs03"+"</th>");out.println("<th>"+"status"+"</th>");
while(b){out.println("<tr>");out.print("<td>"+rs.getString(3)+"</td>");out.print("<td>"+rs.getString(4)+"</td>");out.print("<td>"+rs.getString(5)+"</td>");out.print("<td>"+rs.getString(6)+"</td>");out.println("</tr>");b=rs.next();}out.println("</table>");}catch(SQLException ex){ out.println("error in connection");}finally{try{if(rs!=null)rs.close();if(stmt!=null)stmt.close();if(connect!=null)connect.close();}catch(SQLException e){ }}out.println("</center>");out.println("</body></html>");}}
HTML CODE:
<html><head><title> mark sheet</title></head>
<body><center><h1>Student Mark Sheet</h1></center><form action="serv" method="POST">registration number:<input type="text" name="regno"><input type="submit" value="Submit"><br><br></form></body></html>
OUTPUT:
RESULT:
Thus the program is executed successfully and verified.
EXPT NO: 09 CREATING AND USING IMAGE MAPS
AIM:
To create a web page which includes a map and display the related information when a hot spot is clicked in the map
ALGOTITHM:
Step 1: Create a html file with map tagStep 2: Set the source attribute of the img tag to the location of the image and also set the usemap attributeStep 3: Specify an area with name, shape and href set to the appropriate valuesStep 4: Repeat step 3 as many hot spots you want to put in the mapStep 5: Create html files for each and every hot spots the user will select
<html><head><h1><center>ALL STYLE SHEETS</center></h1><title>USE of INTERNAL and EXTERNAL STYLESHEETS</title><link rel="stylesheet" href="xyz.css" type="text/css"><style type="text/css">.vid{font-family:verdana;font-style:italic;color:red;text-align:center}.ani{font-family:tahoma;font-style:italic;font-size:20;text-align:center;}font{font-family:georgia;color:blue;font-size:20}ul{list-style-type:circle}</style></head><body><ol style="list-style-type:lower-alpha"><b>A.C.S GROUP OF COLLEGES</b><br><br><br><li>Raja Rajeswari Engineering College<li>Dr. M.G.R University and Research Institute<li>Raja Rajeswari College of Engineering,Bangalore<li>Tamilnadu College of Arts and Science</ol><p style="font-size:20pt;color:purple">A.C.S GROUP OF COLLEGES</p><p class="ani">A.C.S Group of colleges is owned by A.C.Shanmugam.<br>It is approved byAICTE(All India Council for Technical Education).It is affliated to Anna University.<br></p><h2 class="vid">Raja Rajeswari Engineering College</h2><br><font>It is an ISO certified Institution</font><br><br><font><h2>List of Courses offered</h2><ul><li>Computer Science and Engineering</li><li>Ece</li><li>mech</li><li>eee</li></ul></font><h3>Results of cse students</h3><table width="100%" cellspacing="2" cellpadding="2" border="5"><tr><th>S.NAME</th><th>MARKS</th><th>RESULT</th>