Re: strange servlet behavior

In the JSDK api:

 public abstract HttpSession getSession(boolean create)

      Gets the current valid session associated with this request, if create
is false or, if necessary, creates a
      new session for the request, if create is true.

      Note: to ensure the session is properly maintained, the servlet
developer must call this method (at least
      once) before any output is written to the response.

With Jigsaw getSession(true) MUST be the first thing you do in doGet().
Jigsaw seems to be more
sensible on that point.

If you put the getSession call before anything else in doGet() it works.

Regards, Benoit.

Manfred Knobloch wrote:

> Hi,
>
> the following Servlet (sample from the o'reilly book)  increments the
> visit-counter on reload and works well with apache mod_jserv 0.9.11,
>
> (apache + mod_jserv - ok)
> http://chagall.diff.uni-tuebingen.de/servlet/SessionTracker
>
> but does not increment its counter when accessed via jigsaw.
>
> (jigsaw 2.0.1 - no incrementing)
> http://chagall.diff.uni-tuebingen.de:8001/servlets/SessionTracker
>
> Is there anything else to configure? I understood the documentation as the
> servlets directory could be used to have Servelets automaticaly installed.
>
> the code
> --------------------------------------------------------------------------
>
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class SessionTracker extends HttpServlet {
>
>   public void doGet(HttpServletRequest req, HttpServletResponse res)
>                                throws ServletException, IOException {
>     res.setContentType("text/html");
>     PrintWriter out = res.getWriter();
>
>     // Get the current session object, create one if necessary
>     HttpSession session = req.getSession(true);
>
>     Integer count = (Integer)session.getValue("tracker.count");
>     if (count == null)
>       count = new Integer(1);
>     else
>       count = new Integer(count.intValue() + 1);
>     session.putValue("tracker.count", count);
>
>     out.println("<HTML><HEAD><TITLE>SessionTracker</TITLE></HEAD>");
>     out.println("<BODY><H1>Session Tracking Demo</H1>");
>
>     out.println("You've visited this page " + count +
>       ((count.intValue() == 1) ? " time." : " times."));
>
>     out.println("<P>");
>
>     out.println("<H2>Here is your session data:</H2>");
>     String nS = new String((session.isNew() ? "NEU" : "ALT"));
>
>     out.println("Session ist  " + nS + "<BR>");
>     String[] names = session.getValueNames();
>     for (int i = 0; i < names.length; i++) {
>       out.println(names[i] + ": " + session.getValue(names[i]) + "<BR>");
>     }
>     out.println("</BODY></HTML>");
>     out.close();
>   }
> }
> ------------------------------------------------------------------------
>
> TIA
>
> Manfred Knobloch
>
> Kompetenzzentrum für Multimedia und Telematik
> am DIFF
> Konrad Adenauer Str. 40
> 72072 Tübingen
>
> tel: ++49 (0)7071 / 979 232
> fax: ++49 (0)7071 / 979 322
> email: manfred_knobloch@diff.uni-tuebingen.de

--
- Benoît Mahé -------------------------------------------------------
                      World Wide Web Consortium (W3C)
                    Architecture domain - Jigsaw Team

  http://www.w3.org/People/Mahe - bmahe@w3.org - +33.4.92.38.79.89
---------------------------------------------------------------------

Received on Tuesday, 2 February 1999 09:34:36 UTC