• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

access session ID from jsp and then java class

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I tried to set a hidden variable in one my jsp using

i could see the value is present in the hidden property sessionId through view source.
But when i say request.getParameter("sessionId"); in my java class the value is null.

Could you please help me with this.

Thanks
Sravani
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

Could you please send your jsp and servlet ?

Thanks
karim
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sravani
Try request.getParameter("jsessionId"). That should work.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't think of any reason to pass the session ID around like this, it should be available from any request received by the web application.

Exactly what are you trying to accomplish?

Bill
 
sravani gogineni
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

William Brogden wrote:I can't think of any reason to pass the session ID around like this, it should be available from any request received by the web application.

Exactly what are you trying to accomplish?

Bill



Hi Bill

I am storing the session id in cookies and the same session id is shared accross all the windows /tabs opened for that session.
But when i log out from main page , a new session is created here. If i click something on the opened tabs it throws error saying the form data is lost. Instead of error i want to redirect to an error page. This is what i want to accomplish. please share your ideas.

Thanks
Sravani
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you think that fiddling with the session ID will solve your problem?

Generally servlet programmers let the servlet container manage the cookie that associates the session with a web app. If all of your jsp and servlets are in the same web application this should be automatic.

it throws error saying the form data is lost.



What is it that "throws error"? Is that your code or something else talking?

Bill
 
sravani gogineni
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi


When the sessionID is stored in cookies the same session is shared among multiple windows/tabs that we open.
So, once we log out from any of the windows and the session ends here. When we re-login , a new session is created.
Now if i submit a form in the open of the opened windows of previous session , the form cannot retrieve all the data from the session object since it overides the new sessionid to the old session id when you click submit button.

So we need to use some hidden variable in the jsp and store the old session id. Compare this value to the new session id and if they are different , show an error page that session is expired.
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like the session mechanism is working as expected.

I suggest you drop using HttpSession for storage of that data and instead create your own session mechanism that will behave like you want.

Create a serializable object to hold all those details and associate it with a unique ID for each user, once the user has signed in, place this ID as a hidden parameter in every form. Save the object to disk using that unique ID for a file name - you can now recover the information from any form submission via the hidden parameter ID. This hidden ID parameter approach completely avoids cookies.

I have used this approach for years - you may be surprised at how fast serialization works.

Bill


 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sravani gogineni wrote:Hi


When the sessionID is stored in cookies the same session is shared among multiple windows/tabs that we open.
So, once we log out from any of the windows and the session ends here. When we re-login , a new session is created.
Now if i submit a form in the open of the opened windows of previous session , the form cannot retrieve all the data from the session object since it overides the new sessionid to the old session id when you click submit button.

So we need to use some hidden variable in the jsp and store the old session id. Compare this value to the new session id and if they are different , show an error page that session is expired.



While showing the error page, do you need any of the data saved in the HTTPSession? If not then you can think of handling that condition where the HTTPSession is null in your action and forward it to an error page.
 
An elephant? An actual elephant. Into the apartment. How is the floor still here. Hold this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic