banto wrote:
Hi gurus,
my problem here is that i'm trying to understnad a servlet code that makes
tomcat to send the
Set-Cookie: JSESSIONID=8BCB60D6F6B9394B4ABD2FDD007BDB39; Path=/store
header.
Now the code is something like:
public class FrontController extends HttpServlet {
public void init() throws ServletException {
HashMap products = new HashMap();
Product p = new Product(1, "Dog", "9.99");
products.put("1", p);
// Store products in the ServletContext
getServletContext().setAttribute("products", products);
}
public void doPost(HttpServletRequest request, HttpServletResponse
response)
.....
and the web.xml is quite standard.
my problem is that i don´t see where the servlet is instructing tomcat to
sent that header.
I would guess right here :
// Store products in the ServletContext
getServletContext().setAttribute("products", products);
Presumably, if you store something in the context, it is because you
want to retrieve it later (or else, what's the point he ?).
Now, Tomcat has no way to know when you'll come back to retrieve it, so
it has to create a session to store this. And to allow you to get that
same session data back later (and not someone else's data), it has to
create some unique key for it. And if you have to be able to get that
data later, you need this key. So Tomcat is nice and sends it to you,
inside of a cookie. This way, you do not need to remember to send the
key back when you next come around, your browser will do it
automatically for you.
Neat, he ?
My other servlets are not issuing that header when running. So what i´m
missing?
Probably, because they do not store anything in their context.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org