hi all, i am trying to set a session cookie. the cookie seems to set fine. a javaservlet sitting on the same port (tomcat port 8080) can retrieve the cookie. and turning the warning on gives the correct warning for the cookie being set. and, yet, when it redirects to any other page on our site, the cookie doesn't show up. again, the retreiving servlet can retreive those cookies set by other pages/processes on our site but not the other way around. i attach the code below. any suggestions? thanks in advance. sanjay
[This message has been edited by Sanjay Anand (edited April 23, 2001).]
Take a Minute, Donate an Hour, Change a Life
Thanks for the reply Maha Anna. I have tried to comment that line and the result is the same. Indeed, you are correct about the fact that cookies are returned only to the host which saved them. But the documentation also says:
a domain name name begins with a dot (".foo.com") and means that hosts in that DNS zone ("www.foo.com", but not "a.b.foo.com") should see the cookie. By default, cookies are only returned to the host which saved them.
I take this to mean that if the domain name where the servlet resides, in my case, is something like "www.foo.com:8080/servlet", it should be accessible to others in the 'DNS zone' mentioned in the documentation. i.e. all the pages in "www.foo.com". In other words, it should be possible to 'diminish' the dns zone if not transform it. Doesn't that make sense? If not, what's the point of setting cookies anyway? Sanjay
i'm not sure i understand the thrust of what you're saying, manav. the simple question here is: is it possible to set a domain that can be accessible to other pages in the same site? other pages, that is, that are not running on the tomcat or jrun server that is being used. and, if so, then what am i doing wrong? why is it not happening? again, i'd appreciate any help.
Sanjay, I made a small test for you. Turns out that, we may have to write cookie.setPath("/") , to make the browser to return this cookie for all resources under "/" in the same server from where the cookie originated. In other words, if "sevletA" in http://localhost:8080/MISApp/servlet/ServletA sets a cookie named "cookieA", in order to make this "cookieA" to be accessed in "http://localhost:8080/MISApp/Login/showCookies.jsp" , we have to write cookie.setPath("/") in the cookie creation/setting code in "ServletA". Here is the code which I tested. You also cut and paste this code and test to make sure if ServletA sets a cookie, it can retrived from another jsp in this server. Since I am able to view those cookies from showCookies.jsp, I would like you also to make the test, so that we can continue from there on. If you also succeed in this test, then try to make those "setPath("/") change in your code. Give it a try! [ Copy SetCookies.class file in your ...WEB-INF/classes dir and showCookes.jsp in your jsp dirs where you can call this jsp. You may have to change the "href link" code in SetCookies.java file accordingly. ] regds maha anna
Dear maha anna, I can see now why you have so many fans. Thanks so much for taking the trouble to post the code. And the code works as, actually, did mine. I added the suggested line [cookie.setPath("/")] to my code as well. In my case I wrote a simple cookie-reading servlet rather than a jsp. But the idea was the same. It too sat in something like http://localhost:8080/MISApp/Login/showCookies.jsp. But the critical question for us is whether we can see this cookie in http://localhost/anotherpage.html i.e. can it be accessed by a page *not* sitting on the 8080 portal? that is something i have not been able to make work yet. I will keep working on it and would, again, appreciate further thoughts. Thanks again. Sanjay