Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need to figure out how to get cookies to work

Status
Not open for further replies.

funkguy4

Vendor
Jun 4, 2004
4
US
Hi.
I'm making an application that will access a database and extract prices for the certain parts that the customer requests from the home page. I've created a JavaScript that places a cookie on the customer's system which I then try to access from my servlet. The servlet goes through the database to extract the prices. I'm having trouble getting the cookies to work! I don't know if the cookie isn't being placed properly or it's and issue with my servlet or if it's an issue with Tomcat 5.

I can provide source codes for the HTML, JavaScript, and Servlet. Please help.
 
It sounds like you may be sending the cookie with javascript and then expecting it to be present on the same click to the backend.

The cookie is not available on the request cycle for which it is set (at least when it is set server-side).

So the question is:

1) Is the cookie being set? Turn on cookie alerts in your security settings on the browser to confirm.

2) On SUBSEQUENT requests is the cookie there? You cna check this by hitting your cookie setting page and then going to another servlet that you write that can just check to see if that cookie exists and tell you so.

It really sounds like a request/response thing, your setting a cookie and expecting it to be available in the same session but your using Javascript so the rules may be different there.
 
Thank you!
You are right that I'm setting a JavaScript cookie and that I want to get it on the same click that I set it. How would you advise that I change my setup so that it sets the cookie AND I can retrieve it? Would you recommend a transitional page that serves to redirect to my servlet, which then processes the cookie?
 
Yes, transitional page is the way to go in this scenario or you can simply do a redirect if you don't see the cookie in your page (redirect to self) although that can get into yucky looping issues.

Good luck!
 
funkguy4 :

Did you read my last post in thread877-856405 - I'd be interested to know your setup ...

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top