You are on page 1of 81

PROGRAM:

map.html
<html>

<body>

<p>

<b>

POPULAR PLANETS FROM SOLAR SYSTEM

</p>

<img src="C:\Documents and Settings\All Users\Documents\My Pictures\Sample


Pictures\Blue hills.jpg" width="145" height="126" usemap="#solarmap">

<map id="solarmap" name="solarmap">

<area shape="rect" coords="10,10,40,25" alt="mercury" href="C:\Documents and


Settings\Administrator\Desktop\m.html">

<area shape="rect" coords="35,20,75,55" alt="venus" href="C:\Documents and


Settings\Administrator\Desktop\v.html">

<area shape="rect" coords="65,55,115,85" alt="earth" href="C:\Documents and


Settings\Administrator\Desktop\e.html">

<area shape="rect" coords="90,85,135,120" alt="saturn" href="C:\Documents and


Settings\Administrator\Desktop\s.html">

</map>

<p><b>Note:</b>Some planets from our solar system are displayed here. click on any planet
and you will get some information about them.

</p>

</body>

</html>

m.html
<html>

<body>

Mercury is the nearest planet to the sun.

CS6512 INTERNET PROGRAMMING LABORATORY


It has higher temperature in it rather than other planets.

</body>

</html>

s.html
<html>

<body>

Saturn has an outer ring of dust and gaseous particles in it.

Saturn cannot contain any living organisms in it as it contains poisonous gas at its
atmosphere.

</body>

</html>

v.html
<html>

<body>

Venus is the biggest planet in the solar system.

venus size is thrice the earth size.

</body>

</html>

e.html
<html>

<body>

Earth is the only planet which supports living organisms.

Earth atmosphere consist of various gas present in it.

</body>

</html>

CS6512 INTERNET PROGRAMMING LABORATORY


OUTPUT:

CS6512 INTERNET PROGRAMMING LABORATORY


PROGRAM:

embedded.html
<html xmlns="http//www.w3.org/199/xhtml">

<head>

<title>Embedded style sheet</title>

<style type="text/css">

h1

font_family:arial;

color:GREEN;

h2

font_family:arial;

color:RED;

left:20px;

h3

font_family:arial;

color:BLUE;

h4

font_family:arial;

color:YELLOW;

CS6512 INTERNET PROGRAMMING LABORATORY


</style>

<body bgcolor=VIOLET>

</head>

<h1>

<center>

THIS PAGE IS CREATED BY EMBEDDED STYLE SHEET.

</center>

</h1>

<h2>

THIS PAGE IS ALIGNED LEFT AND COLORED RED.

</h2>

<h4>

THE EMBEDDED STYLE SHEET IS MOST COMMONLY USED STYLE SHEET.

</h4>

<h3>

THIS IS "BLUE COLOR"<a href="embedded1.html">back</a>

</h3>

</body>

</html>

external.html
<html xmlns="http://www.w3.org/199/xhtml">

<head>

<link rel="stylesheet" type="text/css" href="ex.css"/>

<body bgcolor="skyblue">

</head>

<h1 class="special">

CS6512 INTERNET PROGRAMMING LABORATORY


<center>

THIS PAGE IS CREATED USING EXTERNAL STYLE SHEET.

</center>

</h1>

<h2>

THIS IS A ALIGNED LINE IN LEFT AND COLORED RED.

</h2>

<p>

THE EXTERNAL STYLE SHEET IS REPRESENTATION OF A CASCADING STYLE


SHEET. This paragraph is written in monotype corsia font with size 14.

</p>

<h3>

THIS IS BLUE COLOR<a href="embedded.html">color red </a>

</h3>

</body>

</html>

inline.html
<html><body bgcolor="gray">

<h1 style=color:green>This page is created by inline style sheet</h1>

<h2 style=color:red>This page is aligned left and colored red</h2>

<h3 style=color:yellow>The inline style sheet is easiest representation of cascading style


sheet</h3>

<h4 style=color:skyblue>This is blue color line</h4>

</html>

CS6512 INTERNET PROGRAMMING LABORATORY


OUTPUT:

CS6512 INTERNET PROGRAMMING LABORATORY


CS6512 INTERNET PROGRAMMING LABORATORY
PROGRAM CODING

UserInfo.xml

<?xml version="1.0">
<student>
<person-details>
<id>101</id>
<name>akash</name>
<city>chennai</city>
<marks>70</marks>
</person-details>
<person-details>
<id>102</id>
<name>abhi</name>
<city>madurai</city>
<marks>75</marks>
</person-details>
<person-details>
<id>103</id>
<name>bharathi</name>
<city>chennai</city>
<marks>95</marks>
</person-details>
<person-details>
<id>104</id>
<name>chitra</name>
<city>trichy</city>
<marks>80</marks>
</person-details>
<person-details>
<id>105</id>
<name>nancy</name>
<city>chennai</city>
<marks>85</marks>
</person-details>
<person-details>
<id>106</id>
<name>Dorathi</name>
<city>chennai</city>

CS6512 INTERNET PROGRAMMING LABORATORY


<marks>95</marks>
</person-details>
<person-details>
<id>107</id>
<name>Nirosha</name>
<city>madurai</city>
<marks>98</marks>
</person-details>
<person-details>
<id>108</id>
<name>Ranbeer</name>
<city>chennai</city>
<marks>99</marks>
</person-details>
<person-details>
<id>109</id>
<name>karan</name>
<city>pune</city>
<marks>75</marks>
</person-details>
<person-details>
<id>110</id>
<name>Ram</name>
<city>madurai</city>
<marks>89</marks>
</person-details>
</student>

CS6512 INTERNET PROGRAMMING LABORATORY


Inputform.html
<!DOCTYPE html>
<html>
<head>
<title>STUDENT DETAILS</title>
</head>
<body>
<script type=text/javascript>
function Display()
{
if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
xmlhttp.open("GET,"UserInfo.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var x = xmlDoc.getElementsByTagName("person-details");
var key_id=document.getElementById('key').value;

for (i = 0;i <x.length;i++)


{

if(key_id.match( x[i].getElementsByTagName("id")[0].childNodes[0].nodeValue ))
j=i;
}
document.write("<h3>Student details..</h3>");
document.write("<table
border='3'><tr><th>ID</th><th>NAME</th><th>CITY</th><th>MARKS</th></tr>");
document.write("<tr><td>");
document.write(x[j].getElementsByTagName("id")[0].childNodes[0].nodeValue );
document.write("</td><td>");
document.write(x[j].getElementsByTagName("name")[0].childNodes[0].nodeValue );
document.write("</td><td>");
document.write(x[j].getElementsByTagName("city")[0].childNodes[0].nodeValue );
document.write("</td><td>");
document.write(x[j].getElementsByTagName("marks")[0].childNodes[0].nodeValue );
document.write("</td></tr>");
document.write("</table>");

CS6512 INTERNET PROGRAMMING LABORATORY


}
</script>
<form name=myform >
ENTER ID: <input type=text id=key/></br>
<input type=button value=submit onclick=Display()/>
</form>
</body>
</html>

CS6512 INTERNET PROGRAMMING LABORATORY


OUTPUT

CS6512 INTERNET PROGRAMMING LABORATORY


PROGRAM:
HTTP_REQUEST:

import java.io.*;

import java.net.*;

public class HTTP_Request

public static void main(String args[])

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

CS6512 INTERNET PROGRAMMING LABORATORY


{

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());

CS6512 INTERNET PROGRAMMING LABORATORY


OUTPUT:

CS6512 INTERNET PROGRAMMING LABORATORY


PROGRAM:
SMTP:

import java.io.*;

import java.net.*;

public class SocketsmtpClient

public static void main(String[] args)

Socket smtpSocket = null;

DataOutputStream output = null;

BufferedReader input = null;

try

smtpSocket = new Socket("yoursmtpserver.com", 25);

output = new DataOutputStream(smtpSocket.getOutputStream());

input = new BufferedReader(new InputStreamReader(smtpSocket.getInputStream()));

catch (UnknownHostException e)

System.out.println( "Don't know about host: hostname" );

catch (IOException e)

System.out.println(e.getMessage());

if (smtpSocket != null)

CS6512 INTERNET PROGRAMMING LABORATORY


try

output.writeBytes( "HELO\n" );

output.writeBytes( "MAIL From: puntambekar.a@gmail.com\n" );

output.writeBytes( "RCPT To: puntambekar.a@yahoo.com\n" );

output.writeBytes( "DATA\n" );

output.writeBytes( "From:puntambekar.a@gmail.com\n" );

output.writeBytes( "Subject: testing\n" );

output.writeBytes( "Hi How are u?\n" );

output.writeBytes( "\n. \n" );

output.writeBytes( "QUIT" );

String response;

while ((response = input.readLine()) != null)

System.out.println("Response from server: " + response);

if (response.indexOf("OK") != -1)

break;

output.close();

input.close();

smtpSocket.close();

catch (UnknownHostException e)

System.out.println( "Trying to connect to unknown host: " + e);

CS6512 INTERNET PROGRAMMING LABORATORY


}

catch (IOException e)

System.out.println("IOException: " + e);

CS6512 INTERNET PROGRAMMING LABORATORY


OUTPUT:

CS6512 INTERNET PROGRAMMING LABORATORY


PROGRAM:

POP3:
import java.net.*;

import java.io.*;

public class pop3client

public static void main(String[] argc)

Socket soc;

PrintStream output;

DataInputStream input;

String response;

try

soc=new Socket("202.137.237.142",8080);

input=new DataInputStream(new BufferedInputStream(soc.getInputStream()));

output=new PrintStream(new BufferedOutputStream(soc.getOutputStream()),true);

System.out.println("Client EStablishingconnction with server");

response=input.readLine();

System.out.println("From server..." + response);

output.println("USER xyz");

response=input.readLine();

System.out.println("From server..." + response);

output.println("PASS blabla");

response=input.readLine();

System.out.println("from server..." + response);

output.println("LIST 1");

CS6512 INTERNET PROGRAMMING LABORATORY


response=input.readLine();

System.out.println("from server..." + response);

output.println("RETR 1");

response=input.readLine();

System.out.println("from server..." + response);

output.println("QUIT");

response=input.readLine();

System.out.println("From Server..." + response);

soc.close();

System.out.println("client closing connection with server");

catch(Exception e)

System.out.println("Error in connecting to port");

CS6512 INTERNET PROGRAMMING LABORATORY


OUTPUT:

CS6512 INTERNET PROGRAMMING LABORATORY


PROGRAM:
//FTPSERVER
import java.io.*;
import java.net.*;
public class FTPserver10
{
public static void main(String args[])
{
try
{
ServerSocket server=new ServerSocket(10000);
Socket client;
client=server.accept();
InputStreamReader stream=new InputStreamReader(client.getInputStream());
BufferedReader reader=new BufferedReader(stream);
String filename=reader.readLine();
PrintWriter writer=new PrintWriter(client.getOUTPUTStream());
FileInputStream filestream=new FileInputStream(new File(filename));
int ch;
while((ch=filestream.read())!=-1)
{
writer.write(ch);
writer.flush();
}
writer.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

CS6512 INTERNET PROGRAMMING LABORATORY


//FTPCLIENT
import java.io.*;
import java.net.*;
public class FTPclient10
{
public static void main(String args[])
{
try
{
Socket client=new Socket("127.0.0.1",10000);
PrintWriter writer=new PrintWriter(client.getOUTPUTStream());
writer.println("d:\\welcome.txt");
writer.flush();
InputStreamReader stream=new InputStreamReader(client.getInputStream());
BufferedReader reader=new BufferedReader(stream);
String str=null;
while((str=reader.readLine())!=null)
{
System.out.println(str);
}
reader.close();
}
catch(Exception e)
{
System.out.println("Connection is terminated by server");
}
}
}

CS6512 INTERNET PROGRAMMING LABORATORY


OUTPUT:

Welcome.txt

CS6512 INTERNET PROGRAMMING LABORATORY


CS6512 INTERNET PROGRAMMING LABORATORY
PROGRAM:
Server.java

import java.io.*;

import java.util.*;

import java.net.*;

public class Server

static DatagramSocket server_Socket=null;

static LinkedList portNoList=null;

static HashMap portNos=null;

static public void Send_Message(String msg,int port_Number)

throws IOException

byte sendbuffer[]=msg.getBytes();

server_Socket.send(new
DatagramPacket(sendbuffer,sendbuffer.length,InetAddress.getLocalHost(),port_Number));

static public void sendToAll(String msg,int Special_Port_Number)throws IOException

byte sendbuffer[]=msg.getBytes();

Iterator itr=portNoList.iterator();

while(itr.hasNext())

String strPortNo=(String)itr.next();

int portNo=Integer.parseInt(strPortNo);

if(Special_Port_Number!=portNo)

server_Socket.send(new
DatagramPacket(sendbuffer,sendbuffer.length,InetAddress.getLocalHost(),portNo));

CS6512 INTERNET PROGRAMMING LABORATORY


}

public static void main(String[] args)

try

server_Socket=new DatagramSocket(1024);

portNoList=new LinkedList();

portNos=new HashMap();

System.out.println("The Chat Server Started...");

while(true)

byte buffer[]=new byte[1024];

DatagramPacket pkt=new DatagramPacket(buffer,buffer.length);

server_Socket.receive(pkt);

String clientMsg=new String(pkt.getData(),0,pkt.getLength());

if(clientMsg.indexOf("$##$")!=-1)

StringTokenizer st=new StringTokenizer(clientMsg,"$##$");

String clientName=st.nextToken();

String strPortNo=st.nextToken();

int clientPortNumber=Integer.parseInt(strPortNo);

portNoList.add(strPortNo);

portNos.put(clientName,strPortNo);

Send_Message(".........Welcome" + clientName + "!!!.....",clientPortNumber);

sendToAll(clientName + "has joined the Chat Room!!!",clientPortNumber);

CS6512 INTERNET PROGRAMMING LABORATORY


else if(clientMsg.indexOf("!$")!=-1)

StringTokenizer st=new StringTokenizer(clientMsg,"$!");

String clientName=st.nextToken();

String msg="<" + clientName + ">" + st.nextToken();

String portNo=(String)portNos.get(clientName);

if(msg.indexOf("/exit")!=-1)

Send_Message("/exit",Integer.parseInt(portNo));

portNoList.remove(portNo);

portNos.remove(clientName);

msg="......." +clientName + "has left the Chat Room!!!" +"........";

sendToAll(msg,Integer.parseInt(portNo));

catch(Exception ex)

System.out.println(ex.getMessage());

CS6512 INTERNET PROGRAMMING LABORATORY


Client.java

import java.io.*;

import java.net.*;

public class Client implements Runnable

public static void main(String[] args)

try

client_Port=(int)(50000*Math.random());

while(true)

try

client_Socket=new DatagramSocket(client_Port);

catch(BindException e)

client_Port=(int)(50000*Math.random());

while(client_Port<1023||client_Port>65536)

client_Port=(int)(50000 * Math.random());

continue;

break;

CS6512 INTERNET PROGRAMMING LABORATORY


System.out.print("\n Session for client has started. you can terminate it by trying/exit");

System.out.print("\nEnter your name");

BufferedReader buff=new BufferedReader(new InputStreamReader(System.in));

String client_name=buff.readLine();

String Start_Msg=client_name + "$##$" + client_Port;

byte sendBuffer[]=Start_Msg.getBytes();

client_Socket.connect(InetAddress.getLocalHost(),1024);

client_Socket.send(new DatagramPacket(sendBuffer,sendBuffer.length));

Thread th=new Thread(new Client());

th.start();

while(true)

String msg=buff.readLine();

msg= "!$" + client_name + "!$" + msg;

sendBuffer=msg.getBytes();

client_Socket.send(new DatagramPacket(sendBuffer,sendBuffer.length));

if(msg.indexOf( "/exit" )!=-1)

break;

th.join();

buff.close();

}catch(Exception e) {System.out.println(e.getMessage());}

finally

client_Socket.close();

CS6512 INTERNET PROGRAMMING LABORATORY


static DatagramSocket client_Socket=null;

static int client_Port;

public void run()

byte ReceiveBuffer[]=new byte[1024];

while(true)

DatagramPacket pkt=new DatagramPacket(ReceiveBuffer,ReceiveBuffer.length);

try

client_Socket.receive(pkt);

catch(IOException e)

e.printStackTrace();

String msg=new String(pkt.getData(),0,pkt.getLength());

if(msg.indexOf("/exit")!=-1)

break;

System.out.println(msg + "\n");

CS6512 INTERNET PROGRAMMING LABORATORY


OUTPUT:

CS6512 INTERNET PROGRAMMING LABORATORY


PROCEDURE:
1) SETTING OF A PATH

Steps to set path is as follows

A) GO to MY Computer->Right Click->Properties->Advance tab-


>EnvironmentVariables.

B) A Dialog Box will appear.

C) Select new and set the following path, then click OK.

S.no Path variable Path value


1 CATALINA_HOME C:\Program Files\Apache Software
Foundation\Tomcat 7.0\lib\ jsp-api.jar
2 CLASSPATH C:\Program Files\Apache Software
Foundation\Tomcat 7.0\lib\servlet-api.jar
3 JAVA_HOME C:\Program Files\Java\jdk1.6.0_21
4 PATH C:\Program Files\Java\jdk1.6.0_21\bin

2) SAVING FILES IN THE FOLDER

A) Create a new folder html inside the webapps folder.

B) Save the html and java files in the corresponding folder as shown below

The tree Structure is as follows:

C:\program files\Apache Software Foundation\Tomcat 7.0\webapps\html

Filename.html
WEB-INF(folder)
a. Web.xml
b. Classes(folder)
Filename.java

CS6512 INTERNET PROGRAMMING LABORATORY


PROGRAM CODING
//StudentServlet
import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class StudentServlet extends HttpServlet
{
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
Protected void doPost(HttpServletRequest req,HttpServletResponse res) throws
ServletException,IOException
{
Enumeration en=req.getParameterNames();
res.setContentType("text/html");
PrintWriter out=res.getWriter();
while(en.hasMoreElements())
{
String name=(String)en.nextElement();
out.println(name+"=");
String value=req.getParameter(name);
out.println(value+"</br>");
}
out.close();
}
}

CS6512 INTERNET PROGRAMMING LABORATORY


Student.html
<html>
<head>
<title>student information</title>
</head>
<body bgcolor="pink">
<center>
<form action="http://localhost:8080/welcome/StudentServlet" method="post">
<h3>enter the student information</h3>
<table><tr>
<td>roll no:</td>
<td><input type="text" name="rollno" value="" size="25"/>
</td>
</tr><tr>
<td>student name:</td>
<td><input type="text" name="studentname" value=""/>
</td></tr>
<tr>
<td>address:</td>
<td><input type="text" name="address" value""/>
</td></td>
<tr>
<td>phonenumber:</td>
<td><input type="number" name="phonenumber" value=""/>
</td>
</tr><tr>
<td>total marks:</td>
<td><input type="number" name="total" value=""/>
</td></tr>
</table>
<input type="submit" value="submit"/>
</form>
</center>
</body>
</html>

CS6512 INTERNET PROGRAMMING LABORATORY


Web.xml
<web-app>
<servlet>
<servlet-name>StudentServlet</servlet-name>
<servlet-class>StudentServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>StudentServlet</servlet-name>
<url-pattern>/StudentServlet</url-pattern>
</servlet-mapping>
</web-app>

CS6512 INTERNET PROGRAMMING LABORATORY


OUTPUT

CS6512 INTERNET PROGRAMMING LABORATORY


PROCEDURE:
1) SETTING OF A PATH

Steps to set path is as follows

A) GO to MY Computer->Right Click->Properties->Advance tab->EnvironmentVariables.

B) A Dialog Box will appear.

C) Select new and set the following path, then click OK.

S.no Path variable Path value


1 CATALINA_HOME C:\Program Files\Apache Software
Foundation\Tomcat 7.0\lib\ jsp-api.jar
2 CLASSPATH C:\Program Files\Apache Software
Foundation\Tomcat 7.0\lib\servlet-api.jar
3 JAVA_HOME C:\Program Files\Java\jdk1.6.0_21
4 PATH C:\Program Files\Java\jdk1.6.0_21\bin
2) SAVING FILES IN THE FOLDER

A) Create a new folder Applet inside the webapps folder.

B) Save the java files in the corresponding folder as shown below

The tree Structure is as follows:

C:\program files\Apache Software Foundation\Tomcat 7.0\webapps\Applet

WEB-INF(folder)
a) Web.xml
b) Classes(folder)
Filename.java

3) STEPS TO INVOKE APPLET PROGRAM

Step1: Create a servlet in which some string is created for sending it to applet and compile
the program. The Generated class file will be saved in Classes Folder.

Step2: Edit the Web.xml File.

Step3: Now create an applet program which invokes the servlet created in step1 and compile
the Program.

Step4: Execute it Using Appletviewer and the Applet will be loaded which displays the
message obtained from the Servlet.

CS6512 INTERNET PROGRAMMING LABORATORY


PROGRAM CODING
//Appletclient
import java.applet.*;
import java.awt.*;
import java.net.*;
public class AppletClient extends Applet implements ActionListener
{
public void init()
{
Label la=new Label("invoking servlet from applet");
la.setFont(new Font("cocerix",Font_bold,15));
la.setForeground(color.blue);
add(la);
Button b1=new Button("click here to display date info from server");
b1.setBackground(color.black);
b1.setForeground(color.white);
add(b1);
b1.addActionListener(this);
}
public void ActionPerformed(ActionEvent ae)
{
try
{
AppletContent ac= getAppletContent();
URL url=new url("http:\\localhost:8080\welcome\MyServlet");
ac.showdocument(url);
}
catch(Exception e)
{
System.out.println(e);
}
}
}

CS6512 INTERNET PROGRAMMING LABORATORY


//Myservlet
import java.io.*;
import java.util.*;
import javax.servlet.*;
public class MyServlet extends GenericServlet
{
public void service(ServletRequest req,ServletResponse res)throws
ServletException,IOException
{res.setContentType("text/html");
PrintWriter pw=res.getWriter();
Date d=new Date();
pw.println("<html><body bgcolor=blue><h2> Server Response</h2>");
pw.println("<h3>current date& time from the Server</h3>");
pw.println("<b>" + d +"</b></body></html>");
}
}

Web.xml
<web_app>
<servlet>
<servlet_name>Applet</servlet_name>
<servlet_class>MyServer</servlet_class>
</servlet>
<servlet_mapping>
<servlet_name>Applet</servlet_name>
<url_pattern>/MyServer</url_pattern>
</servlet_mapping>
</web_app>

CS6512 INTERNET PROGRAMMING LABORATORY


OUTPUT

CS6512 INTERNET PROGRAMMING LABORATORY


PROCEDURE:

Creating and Connection to Database

1) Creating Database
a) Click Start Programs MS Office MS Access.
b) Select File New Blank Database and save it as Student Database
c) A database window appears. Select create table in design view option.
d) In the table window, enter the fields name and their respective data types.
e) The table is thus created.
f) Select the table and enter the records.
g) Save the table ad data1.

CS6512 INTERNET PROGRAMMING LABORATORY


2) Connecting Database
a) Click Start Settings Control Panel Administrator Tools Data
sources (ODBC).
b) Select the System DSN tab in ODBC Data Source Administrator.
c) Then Click addand Select driver2 MS Access in the window that appears and
Click Finish.

CS6512 INTERNET PROGRAMMING LABORATORY


d) Enter data source name as StudentDatabase and click select tab to Connect
with the Student Database.
e) Click OK and the Connection is established.

f) RUNNING THE PROGRAM:


The JSP File must be saved at C:\your_tomcat_directory\webapps\jsp-
examples.
Create a Folder at this location and in that folder store the above written JSP
file. For example I have created a folder named StudExam at the location
C:\Tomcat\jsp-examples.
Create a Folder at this location and save my JSP file as Exam.jsp.
Then start running your Tomcat Server.
Now open suitable web browser and Execute the JSP program by typing the
URL
http://localhost:8080/jsp-examples/StudExam/Exam.jsp

CS6512 INTERNET PROGRAMMING LABORATORY


PROGRAM:
Exam.jsp

<%@ page language="java" import="java.sql.*"%>

<%@ page import="java.io.*"%>

<%@ page import="java.util.*"%>

<%

String SeatNum,Name;

String ans1,ans2,ans3,ans4,ans5;

int a1,a2,a3,a4,a5;

a1=a2=a3=a4=a5=0;

Connection connect=null;

Statement stmt=null;

ResultSetrs=null;

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

String url="jdbc:odbc:StudentDB1";

connect=DriverManager.getConnection(url,"","");

if(request.getParameter("action")!=null)

SeatNum=request.getParameter("Seat_no");

Name=request.getParameter("Name");

ans1=request.getParameter("group1");

if(ans1.equals("True"))

a1=2;

else

a1=0;

ans2=request.getParameter("group2");

if(ans2.equals("True"))

CS6512 INTERNET PROGRAMMING LABORATORY


a2=0;

else

a2=2;

ans3=request.getParameter("group3");

if(ans3.equals("True"))

a3=0;

else

a3=2;

ans4=request.getParameter("group4");

if(ans4.equals("True"))

a4=2;

else

a4=0;

ans5=request.getParameter("group5");

if(ans5.equals("True"))

a5=0;

else

a5=2;

int Total=a1+a2+a3+a4+a5;

stmt=connect.createStatement();

String query="INSERT INTO


StudentTable("+"Seat_no,Name,Marks"+")VALUES("+SeatNum+","+Name+","+Total+")";

int result=stmt.executeUpdate(query);

stmt.close();

stmt=connect.createStatement();

query="SELECT*FROM StudentTable WHERE Name="+"""+Name+";

rs=stmt.executeQuery(query);

CS6512 INTERNET PROGRAMMING LABORATORY


%>

<html><head><title>Student Mark List</title></head>

<body bgcolor=khaki>

<center>

<h2>Students Marksheet</h2>

<h3>Name of the college:ABC College of Engineering</h3>

<table border="1" cellspacing="0" cellpadding="0">

<tr>

<td><b>Seat_No</b></td>

<td><b>Name</b></td>

<td><b>Marks</b><td>

</tr>

<%

while(rs.next())

%>

<tr>

<td><%=rs.getInt(1)%></td>

<td><%=rs.getString(2)%></td>

<td><%=rs.getString(3)%></td>

</tr>

<%

rs.close();

stmt.close();

connect.close();

%>

CS6512 INTERNET PROGRAMMING LABORATORY


</table>

</center>

<br/><br/><br/>

<table>

<tr><td><b>Date:<%=new java.util.Date().toString()%></td></tr>

<tr><td><b>Signature:X.Y.Z.<b></td></tr>

</table>

<div>

<a href="http://127.0.0.1.8080/jsp-examples/StudExam/Exam.jsp">Click here to go


back</a>

</body>

</html>

<%}else{%>

<html>

<head>

<title>Online Examination </title>

<script language="javascript">

function validation(Form_obj)

if(Form_obj.Seat_no.value.length==0)

alert("Please,fill up the Seat Number");

Form_obj.Seat_no.focus();

return false;

if(Form_obj.Name.value.length==0)

CS6512 INTERNET PROGRAMMING LABORATORY


alert("Please Fill up the name");

Form_obj.Name.focus();

return false;

}return true;

</script>

</head>

<body bgcolor=lightgreen>

<center>

<h1>Online Examination </h1>

</center>

<form action="Exam.jsp" method="post"

name="entry" onSubmit="return validation(this)">

<input type="hidden" value="list" name="action">

<table>

<tr>

<td><h3>Seat Number </h3></td>

<td><input type="text" name="Seat_no"></td>

</tr>

<tr>

<td><h3> Name: </h3></td>

<td><input type="text" name="Name" size="50"></td>

</tr>

<tr>

<td><b>Total Marks:10(Each Q uestion carries equal Marks) </b></td>

<td></td><td></td><td></td><b> Time:15min </b></td>

</tr></table>

CS6512 INTERNET PROGRAMMING LABORATORY


<hr/>

<b>1.Apache is an Open Source WebServer</b></br>

<input type="radio" name="group1" value="True">True

<input type="radio" name="group1" value="False">False <br>

<br/>

<b>2.In Modern PC there is no cache Memory </b></br>

<input type="radio" name="group1" value="True">True

<input type="radio" name="group1" value="False">False <br>

<br/>

<b>3.Tim-Berner Lee is the Originator of Java </b></br>

<input type="radio" name="group1" value="True">True

<input type="radio" name="group1" value="False">False <br>

<br/>

<b>4.JPG is not a video file Extension </b></br>

<input type="radio" name="group1" value="True">True

<input type="radio" name="group1" value="False">False <br>

<br/>

<b>5.HTTP is a statefull Protocol</b></br>

<input type="radio" name="group1" value="True">True

<input type="radio" name="group1" value="False">False <br>

<br/>

<center>

<input type="submit" value="Submit">

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

</center>

</form>

<%}%>

CS6512 INTERNET PROGRAMMING LABORATORY


OUTPUT:

CS6512 INTERNET PROGRAMMING LABORATORY


CS6512 INTERNET PROGRAMMING LABORATORY
PROCEDURE:
1) SETTING OF A PATH

Steps to set path is as follows

A) GO to MY Computer->Right Click->Properties->Advance tab-


>EnvironmentVariables.

B) A Dialog Box will appear.

C) Select new and set the following path, then click OK.

S.no Path variable Path value


1 CATALINA_HOME C:\Program Files\Apache Software
Foundation\Tomcat 7.0\lib\ jsp-api.jar
2 CLASSPATH C:\Program Files\Apache Software
Foundation\Tomcat 7.0\lib\servlet-api.jar
3 JAVA_HOME C:\Program Files\Java\jdk1.6.0_21
4 PATH C:\Program Files\Java\jdk1.6.0_21\bin

2) SAVING FILES IN THE FOLDER

A) Create a new folder Server inside the webapps folder.

B) Save the html and java files in the corresponding folder as shown below

The tree Structure is as follows:

C:\program files\Apache Software Foundation\Tomcat 7.0\webapps\Server

Filename.html
WEB-INF(folder)
c. Web.xml
d. Classes(folder)
Filename.java

CS6512 INTERNET PROGRAMMING LABORATORY


PROGRAM:
lock.html

<html>

<head>

<title>Input Form</title>

</head>

<body>

<center>

<form name="form1" method=get action="http://localhost:8080/suraj/servlet/KeyIPLock">

<table>

<tr>

<td><b>Enter Key</b></td>

<td><input type="text" name="user_key" size="25" value="">

</td>

</tr>

</table>

<input type="submit" value="submit">

</form>

</center>

</body>

</html>

CS6512 INTERNET PROGRAMMING LABORATORY


keyIPLock.java

import java.io.*;

import java.net.*;

importjava.util.*;

importjavax.servlet.*;

public class KeyIPLock extends GenericServlet

public void service(ServletRequestreq,ServletResponse res)throws


ServletException,IOException

res.setContentType("text/plain");

PrintWriter out=res.getWriter();

String userKey=req.getParameter("user_key");

String key=getInitParameter("key");

String host=req.getServerName();

String HostIP="";

long result=0;

int port=req.getServerPort();

if(key==null)

out.println("*********");

try

InetAddress IP=InetAddress.getLocalHost();

HostIP=IP.getHostAddress();

String[] ipAddressInArray=HostIP.split("\\.");

CS6512 INTERNET PROGRAMMING LABORATORY


for(inti=3;i>=0;i--)

longip=Long.parseLong(ipAddressInArray[3-i]);

result |= ip<<(i*8);

result=result+port;

catch(UnknownHostException e)

out.println(e);

long k=Long.parseLong(userKey);

out.println("key submitted by user="+k);

out.println("key present as init parameter ="+result);

if(k==result)

out.println("authentic access Request is handled!!");

else

out.println("Error!!1 unauthorized access");

}}

CS6512 INTERNET PROGRAMMING LABORATORY


Web.xml

<servlet>

<init-param>

<param-name>key</param-name>

<param-value>3232267905</param-value>

</init-param>

<servlet-name>keyIPLock</servlet-name>

<servlet-class>keyIPLock</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>keyIPLock</servlet-name>

<url-pattern>/servlet/keyIPLock</url-pattern>

</servlet-mapping>

CS6512 INTERNET PROGRAMMING LABORATORY


OUTPUT: (RUN 1)

CS6512 INTERNET PROGRAMMING LABORATORY


OUTPUT: (RUN 2)

CS6512 INTERNET PROGRAMMING LABORATORY


PROCEDURE:
1) SETTING OF A PATH

Steps to set path is as follows

A) GO to MY Computer->Right Click->Properties->Advance tab-


>EnvironmentVariables.

B) A Dialog Box will appear.

C) Select new and set the following path, then click OK.

S.no Path variable Path value


1 CATALINA_HOME C:\Program Files\Apache Software
Foundation\Tomcat 7.0\lib\ jsp-api.jar
2 CLASSPATH C:\Program Files\Apache Software
Foundation\Tomcat 7.0\lib\servlet-api.jar
3 JAVA_HOME C:\Program Files\Java\jdk1.6.0_21
4 PATH C:\Program Files\Java\jdk1.6.0_21\bin

2) SAVING FILES IN THE FOLDER

A) Create a new folder html inside the webapps folder.

B) Save the html and java files in the corresponding folder as shown below

The tree Structure is as follows:

C:\program files\Apache Software Foundation\Tomcat 7.0\webapps\html

Filename.html
WEB-INF(folder)
e. Web.xml
f. Classes(folder)
Filename.java

CS6512 INTERNET PROGRAMMING LABORATORY


PROGRAM:
//Sessiontracking
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Sessiontracking extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws
ServletException,IOException
{
res.setContentType("text/html");
HttpSession session=req.getSession();
String heading;
Integer cnt=(Integer)session.getAttribute("cnt");
if(cnt==null)
{
cnt=new Integer(0);
heading ="welcome you are accessing the page for first time";
}
else
{
heading="welcome once again";
cnt=new Integer(cnt.intValue()+1);
}
session.setAttribute("cnt",cnt);
PrintWriter out=res.getWriter();
out.println("<html>");
out.println("<head>");
out.println("</head>");
out.println("<body bgcolor=pink>");
out.println("<center>");
out.println("<h1>"+heading+"</h1>");
out.println("<h2>the number of previous access ="+cnt+"</h2>");
out.println("</center>");
out.println("</body>");
out.println("</html>");
}}

CS6512 INTERNET PROGRAMMING LABORATORY


Hitcountdemo.html
<html>
<head>hai</head>
<body bgcolor=pink>
<form action ="http://localhost:8080/pri29/Ses29" method="get">
<p>welcome to java lab</p>
<input type="submit" value="click here"/>
</form>
</body>
</html>

Web.xml
<web-app>
<servlet>
<servlet-name>Ses29</servlet-name>
<servlet-class>Ses29</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Ses29</servlet-name>
<url-pattern>/Ses29</url-pattern>
</servlet-mapping>
</web-app>

CS6512 INTERNET PROGRAMMING LABORATORY


OUTPUT:

CS6512 INTERNET PROGRAMMING LABORATORY


CS6512 INTERNET PROGRAMMING LABORATORY
PROCEDURE:
1) SETTING OF A PATH

Steps to set path is as follows

A) GO to MY Computer->Right Click->Properties->Advance tab-


>EnvironmentVariables.

B) A Dialog Box will appear.

C) Select new and set the following path, then click OK.

S.no Path variable Path value


1 CATALINA_HOME C:\Program Files\Apache Software
Foundation\Tomcat 7.0\lib\ jsp-api.jar
2 CLASSPATH C:\Program Files\Apache Software
Foundation\Tomcat 7.0\lib\servlet-api.jar
3 JAVA_HOME C:\Program Files\Java\jdk1.6.0_21
4 PATH C:\Program Files\Java\jdk1.6.0_21\bin

2) SAVING FILES IN THE FOLDER

A) Create a new folder WebPage inside the webapps folder.

B) Save the html and java files in the corresponding folder as shown below

The tree Structure is as follows:

C:\program files\Apache Software Foundation\Tomcat 7.0\webapps\WebPage

Filename.html
WEB-INF(folder)
1) Web.xml
2) Classes(folder)
Filename.java

CS6512 INTERNET PROGRAMMING LABORATORY


PROGRAM:
LoginForm.html

<html>

<head>

<body>

<div align="center">

<br><br>

<form action="http://localhost:8080/suraj/servlet/LoginServlet"method="post">

Enter Username:

<input type="text"value=""name="User">

<br><br>Enter password:

<input type="password"value=""name="Password">

<br><br>Enter CardID:

<input type="text"value=""name=CardID">

<br><br><br>

<input type="submit"value="Login">

</form>

</div>

</body>

</html>

LoginServlet.java

import java.io.*;

importjavax.servlet.*;

importjavax.servlet.http.*;

public class LoginServlet extends HttpServlet

CS6512 INTERNET PROGRAMMING LABORATORY


protected void doPost(HttpServletRequestreq,HttpServletResponse res) throws

ServletException,IOException

res.setContentType("text/html");

PrintWriter out=res.getWriter();

String usr=req.getParameter("User");

String pwd=req.getParameter("Password");

String card=req.getParameter("CardID");

boolean flag=true;

String[] userID=getInitParameter("usernames").split(",");

String[] password=getInitParameter("passwords").split(",");

String[] cardids=getInitParameter("cardIDs").split(",");

inti;

for(i=0;i<userID.length;i++)

if(userID[i].equals(usr)&&password[i].equals(pwd)&&cardids[i].equals(card))

flag=true;

Cookie MyCookie=new Cookie("CurrentUser",usr);

MyCookie.setMaxAge(60*60);

res.addCookie(MyCookie);

res.sendRedirect("http://localhost:8080/suraj/servlet/LoginSucess");

if(flag==false)

out.println("<h4>Invalid user,Please try again by clicking following link</h4>");

CS6512 INTERNET PROGRAMMING LABORATORY


out.println("<a href='http://localhost:8080/suraj/LoginForm.html'>"+"LoginForm.html");

LoginSuccess.java

import java.io.*;

importjavax.servlet.*;

importjavax.servlet.http.*;

public class LoginSuccess extends HttpServlet

protected void doGet(HttpServletRequestreq,HttpServletResponse res)

throwsServletException,IOException

Cookie[] my_cookies=req.getCookies();

res.setContentType("text/html");

PrintWriter out=res.getWriter();

out.println("<br>");

String userName=null;

if(my_cookies!=null)

for(Cookie cookie:my_cookies)

if(cookie.getName().equals("CurrentUser"));

userName=cookie.getValue();

CS6512 INTERNET PROGRAMMING LABORATORY


out.print("<h3>Login Success !!!Welcome</h3>");

out.print("<h2>This is shopping cart for"+userName+"</h2>");

out.close();

Web.xml

<servlet>

<init-param>

<param-name>usernames</param-name>

<param-value>user1,user2,user3</param-value>

</init-param><init-param>

<param-name>passwords</param-name>

<param-value>pwd1,pwd2,pwd3</param-value>

</init-param>

<init-param>

<param-name>cardIDs</param-name>

<param-value>111,222,333</param-value>

</init-param>

<servlet-name>LoginServlet</servlet-name>

<servlet-class>LoginServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>LoginServlet</servlet-name>

<url-pattern>/servlet/LoginServlet</url-pattern>

</servlet-mapping>

<servlet>

CS6512 INTERNET PROGRAMMING LABORATORY


<servlet-name>LoginSuccess</servlet-name>

<servlet-class>LoginSuccess</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>LoginSuccess</servlet-name>

<url-pattern>/servlet/LoginSuccess</url-pattern>

</servlet-mapping>

CS6512 INTERNET PROGRAMMING LABORATORY


OUTPUT:

CS6512 INTERNET PROGRAMMING LABORATORY


CS6512 INTERNET PROGRAMMING LABORATORY
JSP STRUTS FRAMEWORK USING NETBEANS

AIM:

PROCEDURE :-
Step1:- Open the Netbeans6.9.1 IDE from desktop.

Step2:- Select file->new project. From categories, choose java weband from projects, select
web application. Click next->give name as Strutsdemo->click next.

Step 3:- Select the server as tomcat5.5 and give the user name and password. ->click next.

Step 4:- Select the framework as Struts 1.3.10. ->click finish.This creates one project
Strutsdemo in the project window.

Step5:- In the structure of the Strutsdemo from the project window select index.jsp and
web.xml verify the contents of those files.

Step6:- In the structure of the Strutsdemo from the project window select source packages-
>Applicationresource.properties.Then specify the content to be displayed on the web page in
the welcome message field

Step7:- Start the tomcat5.5 server.

Step8:-Run the project by clicking run option.

CS6512 INTERNET PROGRAMMING LABORATORY


OUTPUT:

CS6512 INTERNET PROGRAMMING LABORATORY


SPRING USING NETBEANS

AIM:

PROCEDURE:
Step1:- Open the Netbeans6.9.1 IDE from desktop.

Step2:- Select file->new project. From categories, choose java weband from projects, select
web application. Click next->give name as springdemo->click next.

Step 3:- Select the server as Glassfisv3. ->click next.

Step 4:- Select the framework as Spring Framework 4.0.1 ->click finish.This creates one
project Strutsdemo in the project window.

Step5:- In the structure of the springdemo from the project window select web.xml
.verify the contents of that file

Step6:- In the structure of the springdemo from the project window select index.jsp .Then
specify the content to be displayed on the web page

Step7:- Start the GlassfishV3 server .In service window select server->right click on
GlassfishV3 and click start

Step8:-Run the project by clicking run option.

CS6512 INTERNET PROGRAMMING LABORATORY


HIBERNATE USING NETBEANS

AIM:

PROCEDURE :-
Step1:- Open the Netbeans6.9.1 IDE from desktop.

Step2:- Select file->new project. From categories, choose java weband from projects, select
web application. Click next->give name as hibernatedemo->click next.

Step 3:- Select the server as Glassfisv3. ->click next.

Step 4:- Select the framework as Spring Framework 4.0.1 ->click finish.This creates one
project Strutsdemo in the project window.

Step5:- In the structure of the hibernatedemo from the project window select web.xml verify
the contents of that file.

Step6:- In the structure of the hibernatedemo from the project window select index.jsp
.Then specify the content to be displayed on the web page.

Step7:- Start the GlassfishV3 server .In service window select server->right click on
GlassfishV3 and click start.

Step8:-Run the project by clicking run option.

CS6512 INTERNET PROGRAMMING LABORATORY


OUTPUT:

CS6512 INTERNET PROGRAMMING LABORATORY


PROGRAM:
//jquery.html

<html>

<head>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">

</script>

<script>

$(document).ready(function()

$("button").click(

function()

$("p").hide();

);

});

</script>

</head>

<body>

<h3>This sentence is using heading tag</h3>

<p>this is paragraph</p>

<p>THIS IS ANOTHER PARAGRAPH</p>

<button>click</button>

</body>

</html>

CS6512 INTERNET PROGRAMMING LABORATORY


OUTPUT:

CS6512 INTERNET PROGRAMMING LABORATORY

You might also like