On Tue, 23 Mar 1999, Marc Molitor wrote:

<cut>
> The specification says:
> Returns a Boolean value indicating whether this session is considered to
> be new. A session is considered to be new if it has been created by the
> server and not received from the client as part of this request. This
> means that the client has not "acknowledged" or "joined" the session and
> may not ever return the appropriate session identification information
> when it makes its next request.
<cut>

You may solve your problem just by testing
if(session.getValue("foo") == null) {
}

Instead of isNew().

The JSDK2.0 apidoc has a shorter definition:

'A session is considered to be "new" if it has been created by the server,
BUT the client has not yet been acknowledged joining the session'

wich in the case the browser sends a valid session cookie, even it is newly
created, may be interpreted as an acknowledgement from the client to
join to a (previously) existing session...

Subject to interpretations anyway.  Probably API designers wanted just to
be used as a test if a browser refuses cookies...

If bothered you may try to restart the
browser each time you restart the servlet-runner, so it should forget the
session-cookie.

>
> The code is from Servlet Essentials at
> http://www.novocode.com/doc/servlet-essentials/.
>
> <Snip>
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class ShoppingCartServlet extends HttpServlet
> {
>   protected void doGet(HttpServletRequest req, HttpServletResponse res)
>             throws ServletException, IOException
>   {
>     res.setContentType("text/html");
>     PrintWriter out = res.getWriter();
>     out.print("<HTML><HEAD><TITLE>Online Shop</TITLE>"+
>        "</HEAD><BODY><FORM METHOD=POST>"+
>        "<INPUT TYPE=SUBMIT NAME=foo VALUE="+
>        "\"Put a FOO into the shopping cart\">"+
>        "<INPUT TYPE=SUBMIT NAME=bar VALUE="+
>        "\"Put a BAR into the shopping cart\">"+
>        "<INPUT TYPE=SUBMIT NAME=see VALUE="+
>        "\"See the shopping cart contents\">"+
>        "<INPUT TYPE=SUBMIT NAME=buy VALUE="+
>        "\"Buy the shopping cart contents\">"+
>        "</FORM></BODY></HTML>");
>     out.close();
>   }
>
>   protected void doPost(HttpServletRequest req, HttpServletResponse res)
>
>             throws ServletException, IOException
>   {
>     String msg;
>
>     HttpSession session = req.getSession(true);
>     if(session.isNew())
>     {
>       session.putValue("foo", new int[] { 0 });
>       session.putValue("bar", new int[] { 0 });
>     }
>
>     int[] foo = (int[])session.getValue("foo");
>     int[] bar = (int[])session.getValue("bar");
>
>     if(req.getParameter("foo") != null)
>     {
>       foo[0]++;
>       msg = "Bought a FOO. You now have "+foo[0]+".";
>     }
>     else if(req.getParameter("bar") != null)
>     {
>       bar[0]++;
>       msg = "Bought a BAR. You now have "+bar[0]+".";
>     }
>     else if(req.getParameter("buy") != null)
>     {
>       session.invalidate();
>       msg = "Your order for "+foo[0]+" FOOs and "+bar[0]+
>  " BARs has been accepted. Your shopping cart is empty now.";
>     }
>     else
>     {
>       msg = "You have "+foo[0]+" FOOs and "+bar[0]+
>  " BARs in your shopping cart.";
>     }
>
>     res.setContentType("text/html");
>     res.setHeader("pragma", "no-cache");
>     PrintWriter out = res.getWriter();
>     out.print("<HTML><HEAD><TITLE>Shopping Cart</TITLE></HEAD><BODY>");
>     out.print(msg);
>     out.print("<HR><A HREF=\"");
>     out.print(req.getRequestURI());
>     out.print("\">Back to the shop</A></BODY></HTML>");
>     out.close();
>   }
>
>   public String getServletInfo()
>   {
>     return "ShoppingCartServlet 1.0 by Stefan Zeiger";
>   }
> }
> <Snap>
>
> ___________________________________________________________________________
> 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
>


Cezar Totth                             email:  [EMAIL PROTECTED]
                                        Fax:    (401) 220 33 95
Genesys Software Romania                Phone:  (401) 638 49 44
Stefan Furtuna 169, sect.6
cod 77171, Bucharest
Romania

___________________________________________________________________________
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