Internet Programming LAB MANUAL
Internet Programming LAB MANUAL
TRICHY
Internet Programming
DEPARTMENT OF CSE
LAB MANUAL
add(lblExpected);
add(vertExpected);
add(txtaComments);
add(lblCity);
add(chCity);
add(lblAccompany);
add(lstAccompany);
btnHard.addActionListener(this);
btnSoft.addActionListener(this);
chkC.addItemListener(this);
chkCpp.addItemListener(this);
chkJava.addItemListener(this);
optTcs.addItemListener(this);
optInfosys.addItemListener(this);
optSyntel.addItemListener(this);
horzCurrent.addAdjustmentListener(this);
vertExpected.addAdjustmentListener(this);
chCity.addItemListener(this);
lstAccompany.addItemListener(this);
}
public void actionPerformed(ActionEvent ae) {
String str = ae.getActionCommand();
if(str.equals("Hardware")) {
btnMsg = "Hardware";
}
else if(str.equals("Software")) {
btnMsg = "Software";
}
repaint();
}
public void itemStateChanged(ItemEvent ie) {
repaint();
}
public void adjustmentValueChanged(AdjustmentEvent ae) {
repaint();
}
public void paint(Graphics g) {
g.drawString("Detailed Profile :-", 10, 300);
g.drawString("Field of Interest : " + btnMsg, 10,
320);
Output:C:\IPLAB>javac AWTControls.java
C:\IPLAB>appletviewer AWTControls.java
Output:C:\IPLAB>javac BorderLayoutDemo.java
C:\IPLAB>appletviewer BorderLayoutDemo.java
btnMicrosoft.addActionListener(this);
btnJava.addActionListener(this);
addMouseListener(this);
}
public void mousePressed(MouseEvent me) {
cardLO.next(pnlTech);
}
public void mouseClicked(MouseEvent me) {
}
public void mouseEntered(MouseEvent me) {
}
public void mouseExited(MouseEvent me) {
}
public void mouseReleased(MouseEvent me) {
}
public void actionPerformed(ActionEvent ae) {
if(ae.getSource() == btnMicrosoft) {
cardLO.show(pnlTech, "Microsoft");
}
else {
cardLO.show(pnlTech, "Java");
}
}
}
Output:C:\IPLAB>javac CardLayoutDemo.java
C:\IPLAB>appletviewer CardLayoutDemo.java
imgMb = getImage(getDocumentBase(),
getParameter("recmb"));
imgWsb = getImage(getDocumentBase(),
getParameter("recwsb"));
add(btnRed);
add(btnGreen);
add(btnBlue);
add(lblColor);
add(optFore);
add(optBack);
add(lblImage);
add(optMb);
add(optWsb);
add(txtaComments);
optFore.addItemListener(this);
optBack.addItemListener(this);
optMb.addItemListener(this);
optWsb.addItemListener(this);
btnRed.addActionListener(this);
btnGreen.addActionListener(this);
btnBlue.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
str = cbgColor.getSelectedCheckbox().getLabel() ;
if(ae.getSource() == btnRed &&
str.equals("Background")) {
txtaComments.setBackground(Color.red);
}
if(ae.getSource() == btnRed &&
str.equals("Foreground")) {
txtaComments.setForeground(Color.red);
}
if(ae.getSource() == btnGreen &&
str.equals("Background")) {
txtaComments.setBackground(Color.green);
}
if(ae.getSource() == btnGreen &&
str.equals("Foreground")) {
txtaComments.setForeground(Color.green);
}
if(ae.getSource() == btnBlue &&
str.equals("Background")) {
txtaComments.setBackground(Color.blue);
}
Output:C:\IPLAB>javac ColorPalette.java
C:\IPLAB>appletviewer ColorPalette.java
Output:C:\IPLAB>javac SourceViewer.java
C:\IPLAB>java SourceViewer http://172.16.0.15
Output:C:\IPLAB>javac HeaderViewer.java
C:\IPLAB>javac HeaderViewer.java
C:\IPLAB>java HeaderViewer http://172.16.0.15/default.htm
Content-type: text/html
Content-encoding: null
Date: Fri Sep 19 16:22:51 IST 2008
Last modified: Wed Sep 17 11:34:21 IST 2008
Expiration date: Thu Jan 01 05:30:00 IST 1970
Content-length: 16118
C:\IPLAB>
Output:C:\IPLAB>javac SourceViewer3.java
C:\IPLAB>java SourceViewer http://172.16.0.15/default.htm
HTTP/1.x 200 OK
Key Content-Length: 14895
Key Content-Type: text/html
Key Last-Modified: Sat, 20 Sep 2008 05:55:01 GMT
Key Accept-Ranges: bytes
Key ETag: "80a87d6be51ac91:489"
Key Server: Microsoft-IIS/6.0
Key X-Powered-By: ASP.NET
Key Date: Mon, 06 Oct 2008 02:59:26 GMT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN">
<html>
.
.
.
</html>
Output:C:\IPLAB>javac Assimilator.java
C:\IPLAB>java Assimilator
Output:C:\IPLAB>javac POP3Client.java
C:\IPLAB>java POP3Client
// 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 = new
BufferedWriter(new
FileWriter("Recdfile.txt"));
do
{
fileWriter.write(response);
fileWriter.flush();
}while((response=reader.readLine())!=null);
fileWriter.close();
}
}
public static void main(String[] args)
{
try
{
new FileClient().sendRequestForFile();
}
catch (UnknownHostException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
// FileServent.java
import java.net.*;
import java.io.*;
public class FileServant extends Thread
{
Socket socket;
String fileName;
BufferedReader in;
PrintWriter out;
FileServant(Socket socket) throws IOException
{
this.socket = socket;
in = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
out = new PrintWriter(new
OutputStreamWriter(socket.getOutputStream()));
}
public void run()
{
try
{
fileName = in.readLine();
File file = new File(fileName);
if (file.exists())
{
BufferedReader fileReader = new
BufferedReader(new FileReader(fileName));
String content = null;
while ((content = fileReader.readLine())
!=
null)
{
out.println(content);
out.flush();
}
System.out.println("File Sent...");
}
else
{
System.out.println("Requested File Not
Found...");
out.println("File Not Found");
out.flush();
}
socket.close();
System.out.println("Connection Closed!");
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
}
}
Output:
C:\IPLAB>javac FileServer.java
C:\IPLAB>javac FileClient.java
C:\IPLAB>javac FileServent.java
C:\IPLAB>copy con Sample.txt
Welcome to FTP
C:\IPLAB>java FileServer
Server Waiting...
C:\IPLAB>java FileClient
Connected to Server...
Request Sent...
C:\IPLAB>java FileServer
Server Waiting...
Request Received From /127.0.0.1@2160
Service Thread Started
Server Waiting...
File Sent...
Connection Closed!
C:\IPLAB>type Recdfile.txt
Welcome to FTP
Output:C:\IPLAB>javac UDPServer.java
C:\IPLAB>java UDPServer
Server is Running...
Client: Hello
Welcome
Terminated...
Output:C:\IPLAB>javac UDPClient.java
C:\IPLAB>java UDPClient
Client is Running... Type STOP to Quit
Hello
Server: Welcome
STOP
Terminated...
D:\PostParam\WEB-INF\classes>javac PostParam.java
D:\PostParam\WEB-INF\classes>javac PostParam.java
D:\PostParam\WEB-INF>type web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<!-- JSPC servlet mappings start -->
<servlet>
<servlet-name>PostParam</servlet-name>
<servlet-class>PostParam</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PostParam</servlet-name>
<url-pattern>/PostParam</url-pattern>
</servlet-mapping>
<!-- JSPC servlet mappings end -->
</web-app>
D:\PostParam>jar cvf PostParam.war .
added manifest
adding: PostParam.html(in = 410) (out= 220)(deflated 46%)
adding: WEB-INF/(in = 0) (out= 0)(stored 0%)
adding: WEB-INF/classes/(in = 0) (out= 0)(stored 0%)
adding: WEB-INF/classes/PostParam.class(in = 1156) (out=
643)(deflated 44%)
adding: WEB-INF/classes/PostParam.java(in = 519) (out=
272)(deflated 47%)
adding: WEB-INF/web.xml(in = 674) (out= 314)(deflated 53%)
Step 1:
Step 2:
http://localhost:8080
Step 3:
Step 4:
D:\servlet\WEB-INF\classes>javac Intermediate.java
D:\servlet\WEB-INF\classes>javac AppletToServlet.java
D:\servlet\WEB-INF\classes>javac ServlettoApplet.java
D:\servlet\WEB-INF>type web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<!-- JSPC servlet mappings start -->
<servlet>
<servlet-name>ServletToApplet</servlet-name>
<servlet-class>ServletToApplet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletToApplet</servlet-name>
<url-pattern>/ServletToApplet</url-pattern>
</servlet-mapping>
<!-- JSPC servlet mappings end -->
</web-app>
Step 2:
http://localhost:8080
Step 3:
Step 4:
while(rs.next())
{
out.println("<tr><td>Roll No. : </td>");
out.println("<td>" + rs.getString(1) +
"</td></tr>");
out.println("<tr><td>Name : </td>");
out.println("<td>" + rs.getString(2) +
"</td></tr>");
out.println("<tr><td>Branch : </td>");
out.println("<td>" + rs.getString(3) +
"</td></tr>");
out.println("<tr><td>10th Mark : </td>");
out.println("<td>" + rs.getString(4) +
"</td></tr>");
out.println("<tr><td>12th Mark : </td>");
out.println("<td>" + rs.getString(5) +
"</td></tr>");
}
out.println("</table>");
out.println("</body>");
out.println("</html>");
}
catch (Exception e)
{
System.out.println(e);
}
}
}
Records
D:\Student\WEB-INF\classes>javac Student.java
D:\PostParam\WEB-INF>type web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<!-- JSPC servlet mappings start -->
<servlet>
<servlet-name>Student</servlet-name>
<servlet-class>Student</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Student</servlet-name>
<url-pattern>/Student</url-pattern>
</servlet-mapping>
<!-- JSPC servlet mappings end -->
</web-app>
D:\PostParam>jar cvf Student.war .
D:\Student>jar -cvf Student.war .
added manifest
adding: Student.html(in = 299) (out= 204)(deflated 31%)
adding: WEB-INF/(in = 0) (out= 0)(stored 0%)
adding: WEB-INF/classes/(in = 0) (out= 0)(stored 0%)
adding: WEB-INF/classes/Student.class(in = 2658) (out=
1358)(deflated 48%)
adding: WEB-INF/classes/Student.java(in = 1849) (out=
636)(deflated 65%)
adding: WEB-INF/classes/Student.mdb(in = 139264) (out=
7251)(deflated 94%)
adding: WEB-INF/web.xml(in = 666) (out= 312)(deflated 53%)
Step 1:
Step 2:
Step 3:
http://localhost:8080
Step 4:
Step 5:
Output:-
Xposy12184_</HTML>
!rsid6492051 _51
_par
Lpar