Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to read cookie through JSP?  RSS feed

 
arun mahajan
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody,
I was working on some application which needs to put some information in cookies. I have created the following scenario.
1. Asked some info from user through a JSP file
2. Called a Server on submitting above and made one cookie through it and redirect it to another JSP
3. This next JSP will read the cookie from the machine and will do the required processing.
But to my dipointment I am not able to pick a cookie which is crewated by servlet. Could do same if I make a cookie through JSP only. My questions are:-
1. Can't A Servlet cookie can be picked by JSP and vice-versa.
2. If not is it because both are stored on the different location(directories) of same server. Perhaps different containers are making differance.
3. Can there be some work around for it?
4. I heard about some concept about Web Applications(I don't know even ioita of it) can it be used here? if yes can you pl provide me some reference sites.
regards,
arun
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. There is no difference between JSP and Servle cookies since JSP turn into servlets anyway.
2. Bingo! The likely cause is that the "web applications" are different.
3. You could write a page with a form and hidden variables and a "click here to continue" button.
4. See the servlet API, download from java.sun.com.
Bill
 
arun mahajan
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks William for your reply. Perhaps I am missing at basics and have a bit nore questions:-
1. What do you mean by web application?
2. I am running JRUN. and storing JSp in somewhere in default-app folder while servlets are in defual-app/web-inf/classes folder. Does it make different containers for both?
3. How can I put both servlets and JSP in same container or web application?
I would be highly obliged if you could provide me some reference links for same.
regards,
arun
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best way to understand the implications of "web application" is to download the Servlet and JSP APIs from java.sun.com.
As I recall, the JRun documentation has some discussion of the topic also, assuming you have JRun 3.0 or later.
I think you would have better luck attaching the info to a session and forwarding to the JSP rather than redirecting. I don't remember is a browser will ignore cookie data when it gets a redirect.
Bill
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!