IGNOU - Indira Gandhi National Open University, IGNOU Papers, IGNOU Assignments, IGNOU Results, University, Books, MBA, MCA, Exams, Delhi, India, Course, BCA, Bsc, Msc
 
Google
 
Home IGNOU Papers IGNOU Assignments IGNOU Students Forum IGNOU Articles Indian Education     Registration Login
Indira Gandhi National Open University IGNOU Indira Gandhi National Open University
IGNOU Latest Assignments
IGNOU BCA Assignments MCA 2009
IGNOU BCA Assignments MCA 2008
IGNOU BCA Assignments MCA 2007
IGNOU BCA Assignments MCA 2006
IGNOU Latest Assignments
IGNOU BCA Assignments IGNOU BCA Assignments
IGNOU BCA Assignments IGNOU MCA Assignments
IGNOU MBA Assignmants IGNOU MBA Assignments

IGNOU > IGNOU Assignments > MCA > MCA 2009 Assignments >Laboratory Course

IGNOU MCA Assignments

Question 1 Develop a web page using Servlet for session tracking which ask for your name and address and print a message of welcome along with the number of times you have visited the page. If you are visiting the page first time the message “Welcome! For the first visit” to be displayed on the page.

Ans.
Session.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Session tracker</title>
</head>
<body>
<form action="session_c" method="get">
<div align="center">Session Tracker</div>
<table align="center"><tr>
<td>Name: </td><td><input type="text" name="name"/></td>
</tr>
<tr>
<td valign="top">Address:</td><td> <textarea name="address" cols="30"
rows="5"></textarea></td>
</tr>
<tr><td colspan="2"><input type="submit" value="Submit"></td></tr>
</table>
</form>
</body>
</html>
session_c.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import java.sql.*;
public class session_c extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
String name = req.getParameter("name");
String add = req.getParameter("address");
HttpSession ses=req.getSession();
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
pw.println("<b>Name:</b>"+name+"<br>");
pw.println("<b>Address:</b>"+add+"<br>");
if(ses.isNew())
{
int con = 1;
ses.putValue("count", con);
pw.println("<b>Count:</b>"+con+"<br>");
}
else
{
String c = ses.getValue("count").toString();
int con1 = Integer.parseInt(c)+1;
ses.putValue("count", con1);
pw.println("<b>Count:</b>"+con1+"<br>");
}
}
}

PREVIOUSINDEXNEXT

Indira Gandhi National Open University   Indira Gandhi National Open University

HOME  |   ABOUT US  |  GUEST BOOK | TERMS OF SERVICE | PRIVACY POLICY | CONTACT US

© 2003-2012, IGNOUGuess.com

Website Designing, Website Development, Search Engine Promotion, Web Hosting By: DreamzSop Advertising Private Limited.