sreebrothers.blogspot.com

Welcome to sreebrothers.blogspot.com - A blog that helps engineering students, particularly for Computer Science and Engineering students. Are you a CSE student? Are you finding any study materials? This is your gateway to seek your study materials. This website offers various resources for the students pursuing their courses in affiliated college of Anna University. This included a number of resources in various subjects such as Programming Paradigms, Web Technology, Internet Programming Lab, Java Lab, and so on. In addition to these resources, it offers some university updates, and also included some previous year university question papers. Keep visiting this blog for new updates......

"If someone feels that they had never made a mistake in their life, then it means they had never tried a new things in their life"
Albert Einstein---

CS6512 - Internet Programming Lab

1. IMAGE MAPPING

india.html

<html>
<head>
<title>Image Mapping....</title>
</head>
<body>
<h1 style="text-align:center;font-family:Forte;color:violet">INDIA</h1>
<hr/>
<ul style="font-family:Comic Sans MS;size:3pt;color:darkblue" >
<li>The name India is derived from Indus, which is derived from the Old Persian word Hindu, from Sanskrit</li>
<li>India is the seventh-largest country by geographical area</li>
<li>The second-most populous country with over 1.2 billion people</li>
<li>The most populous democracy in the world</li>
<li>Consisting of 28 states and seven union territories</li>
<li>The name India is derived from Indus, which is derived from the Old Persian word Hindu, from Sanskrit</li>
</ul>
<p style="font-family:Calibri;size:4pt;color:red">
Click On The Hotspots To View More Information About That Particular Places...
</p>
<map name="indiamap">
<area shape="rect" coords="182,482,195,495" href="chennai.html" alt="Click here to get more details">
<area shape="rect" coords="151,159,162,167" href="delhi.html" alt="Click here to get more details">
<area shape="rect" coords="136,328,152,343" href="mumbai.html" alt="Click here to get more details">
<area shape="rect" coords="349,267,363,279" href="kolkatta.html" alt="Click here to get more details">
</map>
<img src="india.jpg" alt="Error on displaying Image" usemap="#indiamap" style="border:0">
</body>
</html>

chennai.html

<html>
<Title>Chennai....</title>
<body>
<p style="font-family:Cambria;color:blue;size:3pt">
Chennai, formerly known as Madras or Madarasapatinam,
is the capital city of the Indian state of Tamil Nadu...
</p>
<table>
<tr>
<td><img src="chennai.jpg" alt="Error on displaying Image"><br/>
    <span style="font-family:Cambria;color:blue;size:3pt">Parry's Corner</span></td>
<td>
<ul style="font-family:Cambria;color:blue;size:2pt">
<li>Chennai being the fourth most populous metropolitan area and the fifth most populous city in India</li>
<li>It is also the world's 36th largest metropolitan area</li>
<li>Chennai's economy has a broad industrial base in the automobile, computer, technology, hardware manufacturing, and healthcare industries</li>
<li>The city is India's second largest exporter of software, information technology (IT) and information-technology-enabled services (ITES)</li>
<li>Chennai is a major centre for music, art and culture in India</li>
<li>The city is known for its classical dance shows and Hindu temples</li>
<li>Cricket is the most popular sport in Chennai</li>
<li>Chennai is the base for the large Tamil movie industry, known as Kollywood, home to most of the movie studios</li>
</ul>
</td>
</tr>
</table>
<a style="font-family:Cambria;color:blue;size:2pt" href="india.html">Home</a>
</body>
</html>

delhi.html

<html>
<Title>Delhi....</title>
<body>
<p style="font-family:Cambria;color:blue;size:3pt">Delhi is the eighth largest
metropolis in the world by population with more than 12.25 million people...</p>
<table>
<tr>
<td><img src="delhi.jpg" alt="Error on displaying Image"><br>
    <span style="font-family:Cambria;color:blue;size:3pt">Lotus Temple</span></td>
<td>
<ul style="font-family:Cambria;color:blue;size:2pt">
<li>Which also includes Noida, Greater Noida, Ghaziabad, Gurgaon and Faridabad along with other smaller nearby towns</li>
<li>Delhi has a maximum length of 51.9 km (32 mi) and the maximum width of 48.48 km (30 mi)</li>
<li>The annual mean temperature is 25 °C (77 °F)</li>
<li>The average annual rainfall is approximately 714 mm (28.1 inches)</li>
</ul>
</td>
</tr>
</table>
<a style="font-family:Cambria;color:blue;size:2pt" href="india.html">Home</a>
</body>
</html>

mumbai.html

<html>
<Title>Mumbai....</title>
<body>
<p style="font-family:Cambria;color:blue;size:3pt">
It is the most populous city in India, and the second most populous city in the world,
with a population of approximately 14 million...
</p>
<table>
<tr>
<td><img src="mumbai.jpg" alt="Error on displaying Image"><br>
    <span style="font-family:Cambria;color:blue;size:3pt">Gateway Of India</span></td>
<td>
<ul style="font-family:Cambria;color:blue;size:2pt">
<li>Mumbai, formerly known as Bombay </li>
<li>Mumbai is the capital of the Indian state of Maharashtra</li>
<li>Mumbai is the commercial and entertainment capital of India</li>
<li>The average annual temperature is 27.2 °C (81.0 °F)</li>
</ul>
</td>
</tr>
</table>
<a style="font-family:Cambria;color:blue;size:2pt" href="india.html">Home</a>
</body>
</html>

kolkatta.html

<html>
<Title>Kolkata....</title>
<body>
<p style="font-family:Cambria;color:blue;size:3pt">Kolkata is the cultural capital of India
and the commercial capital of Eastern India...</p>
<table>
<tr>
<td><img src="kolkata.jpg" alt="Error on displaying Image"><br>
    <span style="font-family:Cambria;color:blue;size:3pt">Victoria Memorial</span></td>
<td>
<ul style="font-family:Cambria;color:blue;size:2pt">
<li>Kolkata, formerly known as Calcutta, is the capital of the Indian state of West Bengal</li>
<li>Before 1690 Kolkata, under direct rule of the Nawab of Bengal Siraj-Ud-Daulah</li>
<li>Kolkata is located in the eastern part India</li>
<li>The annual mean temperature is 26.8 °C (80.2 °F)</li>
</ul>
</td>
</tr>
</table>
<a style="font-family:Cambria;color:blue;size:2pt" href="india.html">Home</a>
</body>
</html>

2. WEB PAGE USING CASCADING STYLE SHEETS (CSS)

cssdemo.html

<html>
<head>
<title>NSCE</title>
<style type="text/css">
#tid1{background-color:gray;width:800px;height:200px;margin-left:15%;margin-right:15%}
#tid2{background-color:gray;width:800px;height:300px;margin-left:15%;margin-right:15%}
img{width:794px;height:200px}
</style>
<link rel="stylesheet" type="text/css" href="extStyle.css"/>
</head>
<body>
<h1 style="margin-left:18%;font-family:Courier New;color:blue">Narayanaguru College of Engineering</h1>
<hr/>
<table id="tid1">
<tr>
<td><img src="ngce.jpg" alt=""></td>
</tr>
</table>
<table id="tid2">
<tr>
<td class="cls1">
<h3 style="font-family:Lucida Sans Unicode;color:blue">About NGCE</h3>
<p>
Narayanaguru College of Engineering came into being
during 2002 - 2003 as a result of the aspirations of a large
number of well-wishers who wanted a global quality Engineering College
to impart value-based and discipline-oriented modern technical
education at affordable cost. The college was promoted by the
charitable trust, Narayanaguru International Institute of Science and Technology,
founded in 1999 by Dr.G.Sidhardhan. The college is located
near Manjaluumoodu, in Kanyakumari District.
</p>
</td>
<td class="cls1" style="vertical-align:top">
<h3 style="font-family:Lucida Sans Unicode;color:blue;text-align:center">Courses Offered</h3>
<div style="font-size:10pt;color:gold;font-family:Lucida Sans Unicode;text-align:justify">
<ul style="list-style:square">
<li>B.E - Automobile Engineering</li>
<li>B.E - Civil Engineering</li>
<li>B.E - Computer Science & Engineering</li>
<li>B.E - Electronics & Communication Engineering</li>
<li>B.E - Electrical & Electronics Engineering</li>
<li>B.E - Mechanical Engineering</li>
<li>M.E-Computer Science and Engineering</li>
<li>M.E-Applied Electronics</li>
<li>M.E-Structural Engineering</li>
<li>MBA-Master of Business Administration</li>
<li>MCA-Master of Computer Application</li>
</ul>
</div>
</td>
</tr>
</table>
</body>
</html>

extStyle.css

body{background-color:black}
.cls1{width:325px;height:300px}
p{font-family:Lucida Sans Unicode;color:silver;font-size:12pt;text-align:justify}

3. IMPLEMENTATION OF FTP

ftpclient.java

import java.net.*;
import java.lang.*;
import java.io.*;
public class ftpclient
{
public static void main(String args[])
{
try
{
FileInputStream f=new FileInputStream("clientfile.txt");
int si=f.available();
Socket s=new Socket("localhost",3000);
PrintStream p=new PrintStream(s.getOutputStream());
for(int i=0;i<si;i++)
{
char r=(char)f.read();
p.print(r);
System.out.print(r);
}
s.close();
System.out.println("\n\nThe File Transferred to server Successfully.............\n");
}
catch(Exception e)
{
System.out.println(e);
}
}
}

ftpserver.java

import java.net.*;
import java.lang.*;
import java.io.*;
public class ftpserver
{
public static void main(String args[])
{
try
{
File f=new File("serverfile.txt");
FileWriter f1=new FileWriter(f);
BufferedWriter bw=new BufferedWriter(f1);
ServerSocket ss=new ServerSocket(3000);
Socket s=ss.accept();
BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
String st=null;
while((st=br.readLine())!=null)
{
System.out.println(st);
bw.write(st);
bw.newLine();
}
br.close();
bw.close();
f1.close();
System.out.println("\n\nThe File Received from the client Successfully.............\n");
}
catch(Exception e)
{
System.out.println(e);
}
}
}

4. SIMPLE CHAT APPLICATION

client.java

import java.io.*;
import java.net.*;
class client
{
public static void main(String args[])throws IOException
{
int cport=789,sport=790;
byte b[]=new byte[1024];
DatagramSocket soc=new DatagramSocket(cport);
DatagramPacket dp=new DatagramPacket(b,b.length);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
InetAddress ia=InetAddress.getLocalHost();
System.out.println("Client is Running... Type 'STOP' to Quit");
while(true)
{
String str=new String(br.readLine());
b=str.getBytes();
if(str.equals("STOP"))
{
System.out.println("Terminated...");
soc.send(new DatagramPacket(b,str.length(),ia,sport));
break;
}
soc.send(new DatagramPacket(b,str.length(),ia,sport));
soc.receive(dp);
String str2=new String(dp.getData(),0,dp.getLength());
System.out.println("Server:"+str2);
}
}
}

server.java

import java.io.*;
import java.net.*;
class server
{
public static void main(String args[])throws IOException
{
int cport=789,sport=790;
byte b[]=new byte[1024];
DatagramSocket ss=new DatagramSocket(sport);
DatagramPacket dp=new DatagramPacket(b,b.length);
BufferedReader dis=new BufferedReader(new InputStreamReader(System.in));
InetAddress ia=InetAddress.getLocalHost();
System.out.println("Server is Running...");
while(true)
{
ss.receive(dp);
String str=new String(dp.getData(),0,dp.getLength());
if(str.equals("STOP"))
{
System.out.println("Terminated...");
break;
}
System.out.println("Client: "+str);
String str1=new String(dis.readLine());
b=str1.getBytes();
ss.send(new DatagramPacket(b,str1.length(),ia,cport));
}
}
}

5. WEB APPLICATION USING XML AND JSP

user.xml

<?xml version="1.0" encoding="utf-8"?>
<userInfo>
<user>
<UID>001</UID>
<Name>AAA</Name>
<Regno>963714104001</Regno>
<Branch>CSE</Branch>
</user>
<user>
<UID>002</UID>
<Name>BBB</Name>
<Regno>963714104002</Regno>
<Branch>CSE</Branch>
</user>
<user>
<UID>003</UID>
<Name>CCC</Name>
<Regno>963714104003</Regno>
<Branch>CSE</Branch>
</user>
<user>
<UID>004</UID>
<Name>DDD</Name>
<Regno>963714104004</Regno>
<Branch>CSE</Branch>
</user>
<user>
<UID>005</UID>
<Name>EEE</Name>
<Regno>963714104005</Regno>
<Branch>CSE</Branch>
</user>
</userInfo>

user.html

<html>
<head>
<title>Student Details</title>
</head>
<body>
<h3 align="center">USER DETAILS</h3>
<hr color="blue">
<form name="frm1" method="GET" action="http://localhost:8080/Ex5/user.jsp">
<table border="1" align="center">
<tr>
<td>Enter User ID:</td>
<td><input type="text" name="uid"></td>
<td><input type="submit" value="SUBMIT"></td>
</tr>
</table>
</form>
</body>
</html>

user.jsp

<%@page contentType="text/html;charset=utf-8" language="java" import="javax.xml.parsers.*,org.w3c.dom.*"%>
<%
try
{
String user=request.getParameter("uid");
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=dbf.newDocumentBuilder();
Document doc=db.parse("http://localhost:8080/Ex5/user.xml");
NodeList id=doc.getElementsByTagName("UID");
NodeList n=doc.getElementsByTagName("Name");
NodeList r=doc.getElementsByTagName("Regno");
NodeList b=doc.getElementsByTagName("Branch");
%>
<h3 align="center">User Details</h3>
<hr color="blue">
<%
for(int i=0;i<r.getLength();i++)
{
if(id.item(i).getFirstChild().getNodeValue().equals(user))
{
%>
<table border="1" align="center">
<tr><td>Name</td><td><%=n.item(i).getFirstChild().getNodeValue()%></td></tr>
<tr><td>Register Number</td><td><%=r.item(i).getFirstChild().getNodeValue()%></td></tr>
<tr><td>Branch</td><td><%=b.item(i).getFirstChild().getNodeValue()%></td></tr>
</table>
<%
}
}
}
catch(Exception e)
{
out.println(e);
}
%>
<a href="user.html">Back</a>

6. INVOKING SERVLETS FROM HTML FORM

client.html

<html>
<head>
<title>Invoking Servlet From HTML</title>
</head>
<body>
<form name="form1" method="post" action="http://localhost:8080/Ex6/server">
<fieldset>
<legend>Registration</legend>
Enter E-mail&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:
<input type="text" name="LoginID" size="25"/><br/><br/>
Enter Password:
<input type="password" name="Password" size="25">
<input type="submit" Value="SUBMIT">
</fieldset>
</form>
</body>
</html>

server.java

import java.io.*;
import java.util.*;
import javax.servlet.*;
public class server extends GenericServlet
{
public void service(ServletRequest req,ServletResponse res)throws ServletException,IOException
{
PrintWriter pw=res.getWriter();
pw.print("<h3>Registration Successfull...</h3>");
Enumeration e=req.getParameterNames();
while(e.hasMoreElements())
{
String str1=(String)e.nextElement();
String str2=req.getParameter(str1);
pw.print(str1+"="+str2+"<br/>");
}
pw.close();
}
}

7. INVOKING SERVLETS FROM APPLETS

AppletClient.java

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
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("Courier",Font.BOLD,15));
la.setForeground(Color.blue);
add(la);
Button b1=new Button("Click Here To Display Date Information From Server");
b1.setBackground(Color.black);
b1.setForeground(Color.white);
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
try
{
AppletContext ac=getAppletContext();
URL url = new URL("http://localhost:8080/Ex7/MyServer");
ac.showDocument(url);
}
catch(Exception e)
{
System.out.println(e);
}
}
}

AppletClient.html

<html>
<head>
<title>Invoking Servlets From Applet</title>
</head>
<body>
<applet code="AppletClient.class" width="400" height="200">
</applet>
</body>
</html>

MyServer.java

import java.io.*;
import java.util.*;
import javax.servlet.*;
public class MyServer extends GenericServlet
{
public void service(ServletRequest req,ServletResponse res)throws ServletException,IOException
{
PrintWriter pw=res.getWriter();
Date d=new Date();
pw.println("<html><body><h2>Srever Response</h2>");
pw.println("<h3>Current Date and Time From Server:</h3>");
pw.println("<b>"+d+"</b></body></html>");
}
}

8. ONLINE EXAMINATION USING SERVLETS

examDB.accdb (Design)


examDB.accdb (Table)


ExamClient.html

<html>
<head>
<title>Online Exam Client</title>
</head>
<body>
<h2>ONLINE EXAMINATION</h2>
<h3>Answer the following questions (5 marks for each correct answer)</h3>
<hr/>
<form name="examForm" method="post" action="http://localhost:8080/Ex8/ExamServer">
1.Who is called as the father of computer?<br/>
<input type="radio" name="ans1" value="Sachin">Sachin
<input type="radio" name="ans1" value="Stuart">Stuart
<input type="radio" name="ans1" value="Charles Babbage">Charles Babbage
<input type="radio" name="ans1" value="Napier">Napier
<br/><br/>
2.C++ was developed by?<br/>
<input type="radio" name="ans2" value="Dennis Ritchie">Dennis Ritchie
<input type="radio" name="ans2" value="None">None
<input type="radio" name="ans2" value="David Ritchie">David Ritchie
<input type="radio" name="ans2" value="John">John
<br/><br/>
3.C was developed by?<br/>
<input type="radio" name="ans3" value="Dennis Ritchie">Dennis Ritchie
<input type="radio" name="ans3" value="Stroustrup">Stroustrup
<input type="radio" name="ans3" value="David Ritchie">David Ritchie
<input type="radio" name="ans3" value="Charles Babbage">Charles Babbage
<br/><br/>
<input type="submit" value="Check Your Result"/>
</form>
</body>
</html>

ExamServer.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class ExamServer extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
try
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
String str1=req.getParameter("ans1");
String str2=req.getParameter("ans2");
String str3=req.getParameter("ans3");
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con = DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\SreekandanK\\Desktop\\IPLab-Netbeans\\examDB.accdb");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT*FROM examTab");
int mark=0,i=1;
while(rs.next())
{
if(i==1)
{
String dbans1=rs.getString(1);
if(str1.equals(dbans1))
{
mark=mark+5;
}
}
if(i==2)
{
String dbans2=rs.getString(1);
if(str2.equals(dbans2))
{
mark=mark+5;
}
}
if(i==3)
{
String dbans3=rs.getString(1);
if(str3.equals(dbans3))
{
mark=mark+5;
}
}
i++;
}
if(mark>=10)
{
pw.print("<h4>Your Mark Is : "+mark+"</h4>");
pw.print("<h3>Congratulations....! You are eligible for the next round...</h3>");
}
else
{
pw.print("<h4>Your Mark is : "+mark+"</h4>");
pw.print("<h3>Sorry....!! You are not eligible for the next round...</h3>");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}

9. DISPLAYING STUDENT'S MARK DETAILS USING SERVLETS

markDB.accdb (Design)


markDB.accdb (Table)



mark.html

<html>
<head>
<title>Three Tier Application</title>
</head>
<body>
<h2>EXAMINATION RESULT</h2><hr/>
<form name="f1" method="get" action="http://localhost:8080/Ex9/mark">
Enter Your Reg.No:
<input type="text" name="regno"/><br/><br/>
<input type="submit" value="SUBMIT"/>
</form>
</body>
</html>

mark.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class mark extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
try
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
String str=req.getParameter("regno");
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con = DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\SreekandanK\\Desktop\\IPLab-Netbeans\\markDB.accdb");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT*FROM markTab WHERE rno="+str);
while(rs.next())
{
pw.print("Register No:"+rs.getObject(1)+"<br/>");
pw.print("Name:"+rs.getObject(2));
pw.print("<table border=1>");
pw.print("<th>SUBJECT</th><th>MARK</th>");
pw.print("<tr><td>Internet Programming</td><td>"+rs.getObject(3)+"</td></tr>");
pw.print("<tr><td>Object Oriented Analysis and Design</td><td>"+rs.getObject(4)+"</td></tr>");
pw.print("<tr><td>Computer Graphics</td><td>"+rs.getObject(5)+"</td></tr>");
pw.print("<tr><td>Theory of Computation</td><td>"+rs.getObject(6)+"</td></tr>");
pw.print("<tr><td>Discrete Mathematics</td><td>"+rs.getObject(7)+"</td></tr></table>");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}

10. AJAX AUTO COMPLETE

stateDB.accdb (Design)


stateDB.accdb (Table)



AutoComplete.html

<html>
<head>
<title>AJAX Demo</title>
<script type="text/javascript">
var req;
function showData(val)
{
var url="http://localhost:8080/Ex10/AutoComplete";
if(val=="")
{
document.getElementById("mydiv").innerHTML="";
return;
}
if(window.ActiveXObject)
{
req=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
req=new XMLHttpRequest();
}
req.onreadystatechange=display;
req.open("POST",url,true);
req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
req.send("state="+val);
}
function display()
{
if(req.readyState==4||req.readyState=="complete")
{
document.getElementById("mydiv").innerHTML=req.responseText;
}
}
</script>
</head>
<body>
Enter Your State:<br/>
<input type="text" name="state" onkeyup="showData(this.value)"><br/>
<div id="mydiv"></div>
</body>
</html>

AutoComplete.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
public class AutoComplete extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
try
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
String s=req.getParameter("state");
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con = DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\SreekandanK\\Desktop\\IPLab-Netbeans\\stateDB.accdb");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select*from stateTab where state like '"+s+"%'");
while(rs.next())
{
pw.println("<div>"+rs.getObject(1)+"</div>");
}
con.close();
stmt.close();
}
catch(Exception e){}
}
}

11. SESSION TRACKING USING HIDDEN FORM FIELDS

home.html

<html>
<head>
<title>Session Tracking - Hidden Form Fields</title>
</head>
<body>
<form method="get" action="http://localhost:8080/Ex11/server1">
<table border="1">
<tr>
<td>Name:</td><td><input type="text" name="userName"/></td>
<td><input type="submit" value="GO"/></td>
</tr>
</table>
</form>
</body>
</html>

server1.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class server1 extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)
{
try
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
String n=req.getParameter("userName");
pw.print("Welcome: "+n);
pw.print("<form action='http://localhost:8080/Ex11/server2'>");
pw.print("<input type='hidden' name='uname' value="+n+">");
pw.print("<input type='submit' value='NEXT'>");
pw.print("</form>");
pw.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

server2.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class server2 extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)
{
try
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
String n=req.getParameter("uname");
pw.print("Hello, "+n);
pw.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

12. SESSION TRACKING TO DISPLAY HIT COUNT

HitCount.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class HitCount extends HttpServlet
{
private int visit=0;
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
HttpSession session=req.getSession(true);
res.setContentType("text/html");
PrintWriter out=res.getWriter();
visit++;
String heading;
if(session.isNew())
{
heading="Welcome, New User";
}
else
{
heading="Welcome Back";
}
out.println("<h2>"+heading+"</h2>");
out.println("<h3>Information on Your Session:</h3>");
out.println("<table border=1><tr><th>Info Type<th>Value</th>");
out.println("<tr><td>Session ID</td><td>"+session.getId()+"</td></tr>");
out.println("<tr><td>Creation Time</td><td>"+new Date(session.getCreationTime())+"</td></tr>");
out.println("<tr><td>Time of Last Access</td><td>"+new Date(session.getLastAccessedTime())+"</td></tr>");
out.println("<tr><td>Number of Visits</td><td>"+visit+"</td></tr>");
out.println("</table>");
}
}

Popular Posts

About Author

Marthandam, Tamilnadu, India