• 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

Loosing sessions between pages

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
The overall mission is to change the world. When you've done that, then you can read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic