tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark Tebong" <mteb...@hupk.com>
Subject RE: Cookies
Date Fri, 21 Nov 2003 14:42:15 GMT
thank you patrick. that worked. 
I assumed a cookie once set was available for the all files in that location.
Is it the same for sessions?

-----Original Message-----
From: Patrick Willart [mailto:patrick@aptitudexchange.com]
Sent: Thursday, November 20, 2003 5:21 PM
To: Tomcat Users List
Subject: RE: Cookies


Since you don't specify the path when you write the cookie it's in
/app/servlet. This means that this cookie can only be read by pages/servlets
in this directory or subdirectories.

Your JSP is in a different directory structure and is not allowed to read
the cookie you wrote.

add cookie.setPath("/") to your servlet to set the cookie path to the root.
Then your JSP (as it is a subdirectory of the root) can read your cookie.

grts,

Patrick

-----Original Message-----
From: Mark Tebong [mailto:mtebong@hupk.com]
Sent: Thursday, November 20, 2003 2:10 PM
To: Tomcat Users List
Subject: Cookies


I set a cookie like this from a servlet (URI=
/app/servlet/myPackage.CookieTest):

		Cookie userCookie = new Cookie("someName", "someValue");
  		userCookie.setMaxAge(60*60*24*365);
  		response.addCookie(userCookie);

I later try to read the cookies using a JSP page like this (URI=
/app/getCookieValue.jsp):

		Cookie[] cookies = request.getCookies();
		Cookie cookie;
		for(int i=0; i<cookies.length; i++)
		{
			cookie = cookies[i];
			out.print(cookie.getName() + "=");
			out.print(cookie.getValue() + "\n");
		}

I get nothing in the results, however, if I try to get and print the
cookie values from the same servlet, I get all cookies that were set and
the sessionid cookie as well. What is going on? How can I set cookies in
a servlet and get their values from a jsp file (btw, the jsp file is in
the same package).

PS Is this the right forum for this question?

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message