Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loosing sessions between pages

 
riya s
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could you please post the code where the session is being lost?

-Rene
 
riya s
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is in my servlet
--------------------------------------------------------------
if(rs.next()){

HttpSession mySession = request.getSession(true);
mySession.setAttribute("user",user);

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

if (rd!=null)
rd.forward(request,response);
}
-------------------------------------------------------------------------

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

page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
session="true"


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) {
response.sendRedirect("LoginPage.jsp");
return;
}


-- 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
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic