Once the ID appears on the URL, the user will be able to use the reload
button.

However, you will need to get the session id onto the URL in the first
place!

A reasonable way of doing this, in this example would be to redirect the
user..

Try something like this,


session = request.getSession(false);

if (session == null) {
  session = request.getSession(true);
  response.sendRedirect(response.encodeURL(....));
  return;
}


What this code does is it checks to see if a session already exists, if it
does
then it does nothing and will continue with your code.. but if a session
does
not exist then it will create one, and then encode it into a URL. The code
will
then ask the users browser to go to that URL, instead of the original URL
that they typed in.

The only difference between the two URLs is that one looks like this

http://www.foo.com/myservlet

and the other one will be

http://www.foo.com/myservlet?jsession=asf2e4234asdf


- Chris.

Brainbench MVP Java2

> -----Original Message-----
> From: Regis Muller [mailto:[EMAIL PROTECTED]]
> Sent: 15 January 2001 13:34
> To: [EMAIL PROTECTED]
> Subject: Re: session tracking
> 
> 
> Thanks but how could it work when clicking on netscape reload button ?
> 
> Christopher Kirk wrote:
> 
> > For session tracking to work, look at the following 2 methods
> >
> > resonse.encodeURL
> > and
> > response.encodeRedirectURL
> >
> > In this way, session tracking will only work when following 
> links because
> > URL re-writting requires a link to modify whereas cookies 
> go by the domain
> > within the HTTP request.
> >
> > So, to make your example work you would have to add
> >
> > <a href="<%=response.encodeURL(address)%>">Click me</a>
> >
> > - Chris
> >
> > Brainbench MVP Java2
> >
> > > -----Original Message-----
> > > From: Regis Muller [mailto:[EMAIL PROTECTED]]
> > > Sent: 15 January 2001 11:05
> > > To: [EMAIL PROTECTED]
> > > Subject: session tracking
> > >
> > >
> > > Im a bit confused cuz I were told session tracking automatically
> > > switched from cookies to url rewriting when cookies arent 
> enabled in
> > > browser but it doesn't seem to work with this simple example :
> > > package coreservlets;
> > >
> > > import java.io.*;
> > > import javax.servlet.*;
> > > import javax.servlet.http.*;
> > > import java.net.*;
> > > import java.util.*;
> > >
> > > /** Simple example of session tracking.
> > >  *  Taken from Core Servlets and JavaServer Pages
> > >  *  from Prentice Hall and Sun Microsystems Press,
> > >  *  http://www.coreservlets.com/.
> > >  *  &copy; 2000 Marty Hall; may be freely used or adapted.
> > >  */
> > >
> > > public class ShowSession extends HttpServlet {
> > >   public void doGet(HttpServletRequest request,
> > >                     HttpServletResponse response)
> > >       throws ServletException, IOException {
> > >     response.setContentType("text/html");
> > >     PrintWriter out = response.getWriter();
> > >     String title = "Session Tracking Example";
> > >     HttpSession session = request.getSession(true);
> > >     String heading;
> > >     // Use getAttribute instead of getValue in version 2.2.
> > >     Integer accessCount =
> > >       (Integer)session.getAttribute("accessCount");
> > >     if (accessCount == null) {
> > >       accessCount = new Integer(0);
> > >       heading = "Welcome, Newcomer";
> > >     } else {
> > >       heading = "Welcome Back";
> > >       accessCount = new Integer(accessCount.intValue() + 1);
> > >     }
> > >     // Use setAttribute instead of putValue in version 2.2.
> > >     session.setAttribute("accessCount", accessCount);
> > >
> > >     out.println(ServletUtilities.headWithTitle(title) +
> > >                 "<BODY BGCOLOR=\"#FDF5E6\">\n" +
> > >                 "<H1 ALIGN=\"CENTER\">" + heading + "</H1>\n" +
> > >                 "<H2>Information on Your Session:</H2>\n" +
> > >                 "<TABLE BORDER=1 ALIGN=\"CENTER\">\n" +
> > >                 "<TR BGCOLOR=\"#FFAD00\">\n" +
> > >                 "  <TH>Info Type<TH>Value\n" +
> > >                 "<TR>\n" +
> > >                 "  <TD>ID\n" +
> > >                 "  <TD>" + session.getId() + "\n" +
> > >                 "<TR>\n" +
> > >                 "  <TD>Creation Time\n" +
> > >                 "  <TD>" +
> > >                 new Date(session.getCreationTime()) + "\n" +
> > >                 "<TR>\n" +
> > >                 "  <TD>Time of Last Access\n" +
> > >                 "  <TD>" +
> > >                 new Date(session.getLastAccessedTime()) + "\n" +
> > >                 "<TR>\n" +
> > >                 "  <TD>Number of Previous Accesses\n" +
> > >                 "  <TD>" + accessCount + "\n" +
> > >                 "</TABLE>\n" +
> > >                 "</BODY></HTML>");
> > >
> > >   }
> > >
> > >   /** Handle GET and POST requests identically. */
> > >
> > >   public void doPost(HttpServletRequest request,
> > >                      HttpServletResponse response)
> > >       throws ServletException, IOException {
> > >     doGet(request, response);
> > >   }
> > > }
> > >
> > > Could anyone help me ? Is there a thing to configure to 
> accept session
> > > tracking ?
> > >
> > >
> > > 
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, email: 
> [EMAIL PROTECTED]
> > >
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, email: [EMAIL PROTECTED]
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, email: [EMAIL PROTECTED]
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to