hello every body,

i tried the SessionSnoop servlet in Jason Hunter book and it seems  i am
doing something
wrong somewhere. i am getting from session.isNew() boolean true in the
second und third request sometime until the eleventh request. i am
invoking the servlet from the same browser window. i have also set the
browser to accept cookies. and from is requestedIdFromCookie i am
getting boolean false. for every subsequent request i am getting a new
HttpSesion object.

thanks a lot for any hint.



here is the code:

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


public class SessionSnoop extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException {

res.setContentType ("text/html");
HttpSession session = req.getSession(true);
PrintWriter out = res.getWriter();


//get the current session object other create one if necessary


boolean b =session.isNew();

Integer count = (Integer)session.getValue("snoop.count");
if (count == null) count = new Integer(1);
else
count = new Integer(count.intValue() + 1);
session.putValue("snoop.count", count);
session.putValue("test","test");

out.println("<HTML><HEAD><TITLE>SessionSnoop</TITLE></HEAD>");
out.println("<BODY><H1>session snoop</H1>");
out.println(" the sesion is new ?" + b + "<br>");
out.println("this is the HttpSession object for this request:" +
session+ "<br>");
out.println("you have visited this page" + count +((count.intValue() ==
1) ? "time."  : "times."));
out.println ("<P>");
out.println (" <H2>hier is your saved session data:</H2>");
String [ ] names = session.getValueNames();
for (int i = 0; i< names.length; i++)
        { out.println(names[i] + ":" + session.getValue(names[i] +"<BR>"));
}
out.println(" why am i getting always null for \"test\"
and\"snoop.count\"" );
out.println("<h3> here are some vital stats on your session</h3>");
out.println("session ID: " + session.getId()+ "<br>");
out.println("new sesion? ::" +session.isNew()+ "<BR>");
out.println("Creation time: " +session.getCreationTime());
out.println("<I>(" + new Date(session.getCreationTime()) + ")</I><BR>");
out.println(" last access time: " + session.getLastAccessedTime());
out.println("<I>(" + new Date(session.getLastAccessedTime())+
")<I><br>");

out.println("Request session ID from cookie: "+
req.isRequestedSessionIdFromCookie() +"<br>");
out.println("why am i getting false by the first request allthough the
cookies are enabled in the browser <br>");
out.println("Request session ID from url: "+
req.isRequestedSessionIdFromUrl() +"<br>");
out.println("Request session ID Valid: "+
req.isRequestedSessionIdValid() +"<br>");
out.println("<H3> Here are all the current session IDs");
out.println(" and the time they hit this page:<h3>");
HttpSessionContext  context = session.getSessionContext();
Enumeration ids = context.getIds();
while(ids.hasMoreElements()){
String id = (String)ids.nextElement();
out.println(id + ":");
HttpSession foreignSession = context.getSession(id);
out.println("this is the foreignsession object::" + foreignSession);
Integer foreignCount=(Integer)foreignSession.getValue("snoop.count");
if (foreignCount==null)out.println("snoop.count is null:"+ (0));
else
 out.println( " snoop.countis not null:" + foreignCount.toString());
out.println("<br>");
}//while zu ende

out.println("<h3> TEST URL REWRITING</h3>");
out.println("click <A href=\"" +res.encodeUrl(req.getRequestURI()) +
"\">here</A>");
out.println("rewriting even when cookies are not supported");

//
out.println("</body></html>");
}
}




and here is the SessionSnoop servlet output(i have changed the servlet
code
a little bit making some output)

the sesion is new ?true
this is the HttpSession object for this
request:com.livesoftware.jrun.JRunSession@ef97b09c
you have visited this page1time.

hier is your saved session data:

test:null snoop.count:null why am i getting always null for "test"
and"snoop.count"

here are some vital stats on your session

session ID: 93585681023683722
new sesion? ::true
Creation time: 935856873727 (Sat Aug 28 17:14:33 GMT+01:00 1999)
last access time: 0 (Thu Jan 01 00:00:00 GMT+00:00 1970)
Request session ID from cookie: true
why am i getting false by the first request allthough the cookies are
enabled in the browser
Request session ID from url: false
Request session ID Valid: true

Here are all the current session IDs and the time they hit this page:

93585681023683722: this is the foreignsession
object::com.livesoftware.jrun.JRunSession@ef97b09c snoop.countis not
null:1

TEST URL REWRITING

click here rewriting even when cookies are not supported

___________________________________________________________________________
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