Hello All,

I am a servlet new one.

In my sample servlet, I use session to count the client number.
here is my servlet:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class SessionServlet extends HttpServlet
{
        String sessionId= null;

        public void doGet (HttpServletRequest request,HttpServletResponse response)
                throws ServletException, IOException
        {
                        Integer visitCounter=null;

                        HttpSession clientSession=request.getSession(true);
                        if (clientSession.isNew())
                        {
                                visitCounter=new Integer(1);
                                clientSession.putValue("visitCounter",visitCounter);
                        }
                        else
                        {
                                visitCounter=new Integer( 
((Integer)clientSession.getValue("visitCounter")).intValue()+1);
                                clientSession.putValue("visitCounter",visitCounter);
                        }

                        sessionId=clientSession.getId();

                        response.setContentType("text/html");
                        PrintWriter out = response.getWriter();

                        out.println("session id:"+sessionId);
                        out.println("<p>");
                        out.print("You have visited "+visitCounter+" times.");
                        out.println("<p>");
                        out.close();

                }

 }

every time I click "refresh" button, the counter will add one, but I
found that wehn I open another browser, the sessionID is still the
previous sessionID, and the counter is not 1 but the previous number
adding one. The browser I use is IE4.0, and Netscape4.5, they have the
same probleom.

Any one who know about that or has any idea about please tell me,
thanks a lot.


Best regards,
 DragonTown                          mailto:[EMAIL PROTECTED]

___________________________________________________________________________
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

Reply via email to