It's not a secret anymore!*
The moose likes JSP and the fly likes Best way to find out of user is logged in Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Best way to find out of user is logged in" Watch "Best way to find out of user is logged in" New topic
Author

Best way to find out of user is logged in

Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
Hi guys, I have to include a page depending on a certain situation. For example, if the user is logged in... Include page A, if not... Include page B. I was wondering if the username or userid stored in a session scoped variable is enough for this task(this is what I've always been doing) or would it be better if I used the session ID and store it in a session scoped variable instead?


SCJP 1.5
http://devpinoy.org/blogs/lamia/ - http://everypesocounts.com/
Rusty Smythe
Ranch Hand

Joined: Aug 09, 2006
Posts: 93
I'd stick with the former (store some user token -- name/id/hash -- in the session). Realize that every session has an ID, even if the user is not logged in.
Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
Thanks, I've been working on a different project and did store the userid in session-scoped variable... Now I have a problem expressing this in JSTL...



even when I'm not logged in... I still get to include the usermenu.jsp. Is there any way I can use the instanceof operator or any similar function?
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Is this page only going to work on authenticated pages, or will public pages, where the userid may not be available, access this page.

Think longterm and flexibility. What happens when that id comes back as null?

I don't mind putting a flag into the session. That seems somewhat innocuous.
Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
That script works on every part of the page... Only that the login screen(table) is replaced by the usermenu when the user is already logged in. What could be a better solution then? That script is inside a file called leftpanel.jsp and leftpanel.jsp is also included in some JSP's liek this...

<jsp:include page="WEB-INF/includes/leftpanel.jsp"/>
Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
Solved... I just put a member variable in my bean named isLoggedIn

then in my JSTL

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Best way to find out of user is logged in
 
Similar Threads
HFSJ 2ed - about <c:set>
jsp: include not working...
controlling browsers back button
Session in jsp
Authenticated user session without cookies- How to implement?