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

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:whentest="${!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.

[1523 byte] By [john_bena] at [2007-10-1 21:38:32]
# 1

Your code looks fine and this should work if the loginUser is set as a session attribute. However are you sure that, that's the case ?

Probably, the code below, from your posting,

HttpSession session=request.getSession(true);

session.setAttribute("loginUser",user);

conditionally sets the session attribute only if the username and pwd are valid ? Have you any if loops around that code ?

cheers,

ram.

Madathil_Prasada at 2007-7-13 3:33:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...