Here is an example to increase counter...
import java.io.*;
import java.util.Enumeration;
import javax.servlet.*;
import javax.servlet.http.*;
public class SessionServlet extends HttpServlet {
public void doGet (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
//Get the session object
HttpSession session = req.getSession(true);
// set content type and other response header fields first
res.setContentType("text/html");
// then write the data of the response
PrintWriter out = res.getWriter();
out.println("<HEAD><TITLE> " + "SessionServlet Output " +
"</TITLE></HEAD><BODY>");
out.println("<h1> SessionServlet Output </h1>");
Integer ival = (Integer) session.getValue("sessiontest.counter");
if (ival==null) ival = new Integer(1);
else ival = new Integer(ival.intValue() + 1);
session.putValue("sessiontest.counter", ival);
out.println("You have hit this page <b>" + ival + "</b> times.<p>");
out.println("Click <a href=" + res.encodeUrl("/servlet/session") +
">here</a>");
out.println(" to ensure that session tracking is working even " +
"if cookies aren't supported.<br>");
out.println("Note that by default URL rewriting is not enabled" +
"due to it's expensive overhead");
out.println("<p>");
out.println("<h3>Request and Session Data:</h3>");
out.println("Session ID in Request: " +
req.getRequestedSessionId());
out.println("<br>Session ID in Request from Cookie: " +
req.isRequestedSessionIdFromCookie());
out.println("<br>Session ID in Request from URL: " +
req.isRequestedSessionIdFromUrl());
out.println("<br>Valid Session ID: " +
req.isRequestedSessionIdValid());
out.println("<h3>Session Data:</h3>");
out.println("New Session: " + session.isNew());
out.println("<br>Session ID: " + session.getId());
out.println("<br>Creation Time: " + session.getCreationTime());
out.println("<br>Last Accessed Time: " +
session.getLastAccessedTime());
out.println("<h3>Session Context Data:</h3>");
HttpSessionContext context = session.getSessionContext();
for (Enumeration e = context.getIds(); e.hasMoreElements() ;) {
out.println("Valid Session: " +
(String)e.nextElement()+ "<br>");
}
out.println("</BODY>");
out.close();
}
public String getServletInfo() {
return "A simple servlet";
}
}
Hope this will help.
Sandip
-------------------------------------------------------------------------------
> --- Partha Bhattacharjee <[EMAIL PROTECTED]>
> wrote:
> > Hello,
> >
> > could anybody give me a small code for demonstrating
> > the use of session s
> >
> > thanks
> > partha
> >
> >
> ___________________________________________________________________________
> > To unsubscribe, send email to [EMAIL PROTECTED]
> > and include in the body
> > of the message "signoff SERVLET-INTEREST".
> >
> > Archives:
> >
> http://archives.java.sun.com/archives/servlet-interest.html
> > Resources:
> >
> http://java.sun.com/products/servlet/external-resources.html
> > LISTSERV Help:
> http://www.lsoft.com/manuals/user/user.html
>
>
> =====
> Cheers ,
>
> Prashant .
> Software Engineer
> Parametric Technology Corporation.
>
> Visit us at www.ptc.com
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Mail - Free email you can access from anywhere!
> http://mail.yahoo.com/
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html