Creating new sessions without invalidate the old one

Sergioc
Sergioc used Ask the Experts™
on
Hi,  I have a link that open a JSP application in other browser. When it start I inicialize some session variables, but if the user clicks again in the link and opens the application again, the news variables replace the originals. ¿How can I start a new session each time the user clicks the link without invalidate the old session? I really need the user can begin new sessions without close and open again the browser with the link to my application.

Thanks a lot for any comment
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mick BarryJava Developer
Top Expert 2010

Commented:
You cannot have multiple sessions objects (for a single session).
To achieve what you want you could create a Hashtable for each 'sub-session' and store variables in there:

session.setAttribute("session1", new Hashtable());
session.setAttribute("session2", new Hashtable());



Hashtable subsession = (Hashtable) session.getAttribute("session1");
String var = (String) subsession.get("myvar");

Author

Commented:
I don`t know if I can use that, Objects.
How Will I distinguish between requests from one subsession or another one, How will I know in which Hashtable I have to look for?

I know I can´t have multiple session objects, I don´t want to do exactly that. Really I want to know if I can locate one point "X" in my application when start other session and LOST contact with the first session , because the user can decide to open a lot of instances of the application in "X".

Thanks for any comments.
Mick BarryJava Developer
Top Expert 2010

Commented:
you pass 'subsession' key in the url or store it as a cookie the same way the actual session id is remembered.
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Author

Commented:
How can I know which one is the best solution?. First: do I have to ask if the browser have the cookies enables?, How can I ask?
Thanks a lot
Java Developer
Top Expert 2010
Commented:
>> I really need the user can begin new sessions without close and open again the browser with the link to my application.

give your application window a name so if user click the link again, it goes to the very same window, which is exactly the same session.
>> you pass 'subsession' key in the url or store it as a cookie the same way the actual session id is remembered.
all cookies will be returned, how can you tell it is from which windows?
Mick BarryJava Developer
Top Expert 2010

Commented:
Good point, so pass the subsession key in the url.

Commented:
try this in your jsp

 Session s = request.getSession(false);

 // This means there is no session yet
 if(s==null)
{
 do whatever;
}
else
{
 request.getSession(true);
do your initialization here
}
 

Commented:
oops it should be

try this in your jsp

Session s = request.getSession(false);

// This means there is no session yet
if(s!=null)
{
do whatever;
}
else
{
s = request.getSession(true);
do your initialization here
}

Author

Commented:
Sorry Objects, there is one way I can pass the subsession ID automatically in all the URLs of the pages?
Most of the URLs are generated for a web designer who doesn´t know JSP, and there is too much URLs in the pages. Do I have to look for all of them?
Can I write one kind of sentence that modify all the URLs of the page?

thanks a lot.
Mick BarryJava Developer
Top Expert 2010

Commented:
>  there is one way I can pass the subsession ID
> automatically in all the URLs of the pages?

No, you will need to implement this yourself.

Distinguished Expert 2018

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Split points between objects and kennethxu

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial