• 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

Stateful & Stateless sessions

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am kind of stuck here. Let me tell you what I did thus far:-

1) I used sessions to keep track of the inputted values and then I discovered that these sessions cannot keep values for more than 2 "hyperlinks". Meaning that, I input a value, press next, enter another value press next and then press two backs and the session information is gone.

2) Then I discovered there is something named stateless sessions and there is something named statefull sessions. And that each session has an ID and that this ID must be passed around to servers in cookies so as for the information to persist.

Then I tried to use ready-made code. Just to test the concept and see whether it would work or not. The code is found at http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/hall/ShowSession.java. And the next thing that I know is that it is telling me it cannot resolve javax.servlet.*. I, of course can download the API and work with it, but, correct me if I am wrong, there is an easier way of doing things.
 
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

Originally posted by Raef Kandeel:
1) I used sessions to keep track of the inputted values and then I discovered that these sessions cannot keep values for more than 2 "hyperlinks". Meaning that, I input a value, press next, enter another value press next and then press two backs and the session information is gone.


If that's the case, something's wrong with your code.
Your session variables will last as long as your session unless you explicitly remove them or overwrite them.


2) Then I discovered there is something named stateless sessions and there is something named statefull sessions. And that each session has an ID and that this ID must be passed around to servers in cookies so as for the information to persist.


There's only one kind of session in the servlet spec.
HTTP, itself is stateless; meaning that a connection to the server is created and destroyed for each and every request. This differs from stateful protocols like FTP and telnet. With these protocols, you make a connection to the server and keep that same connection until you sign out.
The server always knows who you are because you are using the same connection you were using when you signed on.

To mimmick a stateful connection servlet containers pass a session ID to the browser (usually in the form of a cookie) and then use that ID to match your session up with an object stored in memory (on the server) for all subsequent requests. The session object is essentially, a map of name value pairs. You can bind anything to it and then retrieve, by name, it in later requests by calling session.getAttribute.


Then I tried to use ready-made code. Just to test the concept and see whether it would work or not. The code is found at http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/hall/ShowSession.java. And the next thing that I know is that it is telling me it cannot resolve javax.servlet.*. I, of course can download the API and work with it, but, correct me if I am wrong, there is an easier way of doing things.



This problem has nothing to do with sessions.
It has to do with your environment not being set up properly.
[ November 05, 2007: Message edited by: Ben Souther ]
 
Raef Kandeel
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Ben,

Thanks for answering my question. As you can see, I am a newbie and my questions can never be anything but silly. Sorry!


If that's the case, something's wrong with your code.



There goes my code:-

First.jsp



Second.jsp


Third.jsp


I apoligize in advance for any silly things I did/said out of ignorance.
 
Ben Souther
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, no need to apologize.
You're asking reasonable questions.

Can you tell us what variables aren't put and describe exactly when in your clicking sequence, you notice them being removed from session?
 
Raef Kandeel
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I run First.jsp on the server. Then, I enter a username and a password. Then, I press Next, then again, I press Next. Then, I press back, then back. And the username and password values had disappeared.
 
Ben Souther
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
When you click your "back" hyperlink, taking you to page2.jsp,
this block of code is run:


Since clicking on a hyperlink doesn't post the username and password fields, the two are going to be null when this is run, causing this block of code to overwrite what's currently in session.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I bet you got the terms stateful session bean and stateless session bean from EJB discussions. Fortunately, you can immediately forget you ever heard them until you really have to do EJBs one day.

(The spell checker in Firefox wanted "plateful" instead of stateful. I declined. )
 
Raef Kandeel
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, it helped. I got it to work. Is there something named: HttpRequest management? Can anybody explain to me what it is? Thanks.
[ November 06, 2007: Message edited by: Raef Kandeel ]
 
Our first order of business must be 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