Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Retrieving data in session

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I m having one servlet. There is session and i m setting some attributes and as a output it goes to JSP. Here i m not requesting to JSP. So whatever attributes i have set there not getting in JSP. When i give next request for the servlet that time when i generate the output in JSP it gives me back the values. It menas it gives me the values those were there in previous session.

How can i get the values in that session session only.

Thanks in advance.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I m having one servlet. There is session and i m setting some attributes and as a output it goes to JSP. Here i m not requesting to JSP. So whatever attributes i have set there not getting in JSP.


Sorry but what you are trying to express is not very clear. If you've set some attributes in the session, they will be available at any time, until the session is invalidated. So there should be no problem to access them from JSP.
If you could be a little more specific on how you are trying to access the attributes.
 
Vrushali Gore
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See i m having one JSP. From there request is given as src attribute of img to servlet. Where i m setting few values in session and a response generated goes back to JSP(Here i m not generating any request for that JSP as i dont want to reload that JSP, just want to reload that image) where i m interested in values those i have set in servlet session.

But here i get the values those i have set up in previous session.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure I understand the problem But I think you have a cache problem. The src attribute of an image sends a GET request, which is being cached by your client. Try to turn off the cache, using the following method :
http://faq.javaranch.com/view?NoCacheHeaders
 
Vrushali Gore
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess the problem is still not clear. I have a JSP from which image is generated. Here what i m doing as i don't want to regenerate request for JSP transferring the control to servlet via src atttibute and generating response. So response i.e. image which is generated is automatically printed on JSP as it is source for that image. But when i m working in servlet that time setting some values in session which i want in JSP when i come back.

Thanks in adv.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, it sounds like you're confusing "session" scope with "request" scope.

If you only want to store a value long enough to reach a JSP or servlet to which you're fowarding, request scope will do.

If you want the value to persist across requests for that user, then you would use session.

Can you explain exactly what you mean when you say "it goes to jsp"?
Are you using a requestDispatcher to perform a server side forward or are you trying to do this with response.sendRedirect?
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you have 2 problems
1- not getting values in session set in the servlet called by img src attribute
2- when you logged in again with different session you get the values set by previous session rite?

for problem#1
first most important thing is.. if you call servlet src attribute of img and set some values in session there.. and then try to get those values in remaining code of jsp. you will never get the values in JSP set by servlet called via img's arc attribute.
reason is simple. when you access a jsp, what is the life cycle of it. first it will be interpreted into the .java file(if being accessed firt time) and then compiled the .java file..
when you called the jsp its will be executed first all computation.. and rendered a response to browser.. and when browser reaches the tag of img where you mentioned the srvlet in src attribute its request will be sent to server again.. so this request will be sent later than the execution of jsp code. got it?


for the solution of second problem, i feel your session is not being expired..
implement sessionlistner and enumerate list of attributes in session on the event of session created and session destroyed..
As you said when you logged in back you get the values set previously, i think your session is not getting expired..

i hope you have got some pointers for the solution of your problem..

thanks
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic