File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Websphere and the fly likes Loosing sessions between pages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "Loosing sessions between pages" Watch "Loosing sessions between pages" New topic

Loosing sessions between pages

riya s
Ranch Hand

Joined: Feb 28, 2003
Posts: 110
I have absolutely nothing wrong with my code and I checked a 100 times but I am still loosing sessions from one page to other...

I am getting the session okay on one jsp page which has a html form. Once that form is submitted ... I am not changing anything in the session and I just cant get the session in the next Servlet which is called when the form is submitted?

I am using WAS 5 test server under WSAD.

Any ideas?
Rene Smith

Joined: Jun 10, 2004
Posts: 21
could you please post the code where the session is being lost?

riya s
Ranch Hand

Joined: Feb 28, 2003
Posts: 110
There is no particular place...Its happening on everyother page...
I set it and the next page it works but it doesnt work in the next to next page when I do getAttribute even though I dont change it or set it to null...

Like in the servlet I say session.setAttribute("user",name); and the next pahe when I do String user = (String) session.getAttribute("user"); it works but the page after that it gives null...
Sam Easter

Joined: Jan 25, 2005
Posts: 5
Hi Priya,
Please post some code if possible. But otherwise, by the looks of it I think that you are getting a new session on every page, which could be due to that the client has disabled cookies and you also are not using URL rewriting. Thats what comes to my mind

riya s
Ranch Hand

Joined: Feb 28, 2003
Posts: 110
This is in my servlet

HttpSession mySession = request.getSession(true);

RequestDispatcher rd = null;
rd = getServletConfig().getServletContext().getRequestDispatcher("/MM.jsp");

if (rd!=null)

On the MM.jsp I have this... I cant display the <@

contentType="text/html; charset=ISO-8859-1"

I tried removing the above... using just session instead of mySession..

HttpSession mySession = request.getSession(true);
String user = (String)mySession.getAttribute("user");
if(user == null) {

-- HTML FORM HERE IS DISPLAYED AND I am not reredirected to LoginPage

When the form is submitted ... It goes to Post Method of the servlet that the form calls...

I dont want a new session so I have this...

System.out.println("Prints this");

HttpSession mySession = request.getSession(false);
if(mySession != null)
System.out.println("Got session");
user = (String) mySession.getAttribute("user");
It doesnt print Got Session... If I set HttpSession mySession = request.getSession(true); -- It gives me a brand new session not the one from the previous page...

I have no idea why its doing this in WSAD...
riya s
Ranch Hand

Joined: Feb 28, 2003
Posts: 110
Thanks sam...Thank you you did lead me in the right direction.

Actually the client had cookies enabled but there was a option in WSAD which was under the WAS test server's web tab which has options for container... The enable URL Writing and Enable cookies were both disabled... I wonder why they do this?

In the Java Blueprints they recommend HTTPSession and so websphere should have atleast the Cookies option open by default ... But I guess we have to check that everytime...

Thank you again
I agree. Here's the link:
subject: Loosing sessions between pages
It's not a secret anymore!