• Post Reply Bookmark Topic Watch Topic
  • New Topic

can't create cookie using jsp  RSS feed

 
Mathias Nilsson
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's wrong with code below. I've imported javax.servlet.Http.*
 
Tim Baker
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i can't see anything. perhaps there is an error in other code such as committing the response before this code is used or perhaps the browser is refusing the cookie ?
 
Mathias Nilsson
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is that? I just went through the cookie directory and javaranch , google
and so on has cookies created on my computer. If i delete them and
visit the pages again the cookies will be there.
I'm very confused. Is there a simple cookie sample code that I can use other then mine?
// Mathias
 
Tim Baker
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i recommend you use MozillaFirebird browser for your development and set it so that it prompts you whenever a site asks to set a cookie, and even lets you view the cookie before you accept it. this is more reliable than trying to look for them on your hard drive because your browser is not guarenteed to store them when you expect.
i would first of all look at your other code and make sure something isn't interfering with the response
 
Mathias Nilsson
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again!
Thanks for you're responses. After the page directive and the import directive I have an jsp include directive.

If I remove this the cookie gets created. Can anyone explain this to me. I know that it is something wrong with the flush="true". What does flush=true means??
Thanks
//Mathias
 
Tim Baker
Ranch Hand
Posts: 541
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
from sun:
flush="true | false"
If the page output is buffered and the flush attribute is given a true value, the buffer is flushed prior to the inclusion, otherwise the buffer is not flushed. The default value for the flush attribute is false.

when you are including that .jsp file it is writting something out as a response and cookies must come as part of the header and so must be done before the response starts being sent.
 
Mathias Nilsson
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
// Mathias
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!