How to test the existence of a session object in JSP by using struts/jstl
843838Aug 22 2005 — edited Aug 22 2005Please 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.