File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Session Problem in Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session Problem in Tomcat" Watch "Session Problem in Tomcat" New topic
Author

Session Problem in Tomcat

Balaji
Greenhorn

Joined: Oct 16, 2003
Posts: 5
Hi
Iam using tomcat for my application. in my code i specified as
sessobj = request.getSession(true);
But this creates new session object within the same browser. so i am not able to use the existing session.
Can anybody provide a solution for this? it would be very helpful for me.
Thanks
Balaji Jayaram
Lakshmi Dasari
Ranch Hand

Joined: Mar 03, 2003
Posts: 35
Use request.getSession() instead. This will return an existing session if one exists or creates a new one. Here is what the specification says.

public HttpSession getSession()
Returns the current session associated with this request, or if the request does not have a session, creates one.
Returns:
the HttpSession associated with this request


Lakshmi
Amit KumarS
Ranch Hand

Joined: Oct 10, 2003
Posts: 100
Hi...
as far as getting sesison from request object is concerned..
resuest.getSession() is a correct way.. but this is overloaded method and takes has two forms..
1. getSession() and
2. getSession(boolean create)
first method is same as calling getSession(true), cause both return a session if there is already a session created and return new session if there is no session earlier
but if u call getSession(false) then it returns a session which was there.. but returns null if there is no session...
so there if u r using request.getSesison(true) then it will create a new sesison if one not already present... so check your code properly as there may be error somewhere else...
or you can specify your problem in more detailed manner so that we can help
Thanks
Amit


****************************<br />In 24 hrs Earth rotates once on its Axis.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Session Problem in Tomcat