aspose file tools*
The moose likes Servlets and the fly likes how to use session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to use session" Watch "how to use session" New topic
Author

how to use session

Harshit Rastogi
Ranch Hand

Joined: Apr 15, 2008
Posts: 131
Hi
I am new to servlet. I am trying to create an login page. Now i want that everytime a user logs in i should create a session using the user id and reuse it if the user logs in again.

How should i approach for it.

a block of code for this will be a great help
Thanks


<a href="http://technologiquepanorama.wordpress.com" target="_blank" rel="nofollow">My Techie Blog</a><br /><a href="http://www.java-questions.com" target="_blank" rel="nofollow">Java Questions</a>
Veeresh Hosur
Ranch Hand

Joined: Dec 18, 2007
Posts: 32
You can create Session object by

HttpSession session = request.getSession(true);

If there is session object then the same object will be returned if not a new session object will returned.

Please read servlet api document for more Info.

Thanks
Veeresh
abhishek pendkay
Ranch Hand

Joined: Jan 01, 2007
Posts: 184
Harshit
Now i want that everytime a user logs in i should create a session using the user id and reuse it if the user logs in again


That is not a good idea... are you trying to say that if a user logs in today you will create a session then the user logs out and does not login again for one week you will keep the session object for one week..???
that is not how a session should be used.. you would be better if you created a new session each time the user logs in


The significant problems we face cannot be solved by the same level of thinking which created them – Einstein
SCJP 1.5, SCWCD, SCBCD in the making
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to use session