Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to test the existence of a session object in JSP by using struts/jstl

843838Aug 22 2005 — edited Aug 22 2005
Please any body can help me to get out of the loop. I am using struts for my web application. The login screen will redirect it to a action class where after successfull verification I am setting the session object, which is a java object which contains members like useName and email. Now I will check in the login page it self whether user logged in or not. If yes show the message as "Welcome <usename>" else show him the link login.

In my Action Class I wrote the code as

LoginUser user = new LoginUser(username,email);
..........................................
...........................................
HttpSession session=request.getSession(true);
session.setAttribute("loginUser",user);
.....................................

In the JSP Page code is like this

<c:choose>
<c:when test="${!empty loginUser}" >
Welcome ${loginUser.userName}
</c:when>
<c:otherwise>
<html: link action="/Login.do">Login</html:link>
</c:otherwise>
</c:choose>

This JSP will be in the Header of my View. As long as the user is valid and logged in then the Header will show the Welcome note other wise the Login link. I am using the struts tiles for my View.

Can any body help me why this piece of code is not working as expected. It always shows the Login link even though the user is logged in.
I spent two sleepless nights solving the problem. Please help me.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 19 2005
Added on Aug 22 2005
1 comment
345 views