Reputation: 2794
I have index.jsp
, i need to include a header.jsp
in that.The problem is - header.jsp contains dynamic menu (for loggedIn users and for non-loggedIn users) i can check if user is logged in or not using session in index.jsp
. but not in header.jsp
How can i include header in this situation ??
Can i access session object in header.jsp
anyway?
Upvotes: 1
Views: 562
Reputation: 94653
Add conditional statement in header.jsp
. (Presume that the you've session key named islogged
that represent a status whether a user is logged or not)
<c:choose>
<c:when test="${not empty islogged}">
//html markup for logged user
</c:when>
<c:otherwise>
//html markup for not logged user
</c:otherwise>
</c:choose>
EDIT :
@I don't have any session key maintained..but I would like to ..How can I do this?
Create a servlet, compare username and password in doPost() method, set session key-value if user is authenticated.
You can verify a user (whether he/she is logged or not) by checking a session key-value in filter.
Upvotes: 1
Reputation: 754
you can put expression into header file, that checks you logged in condition. For example.
<%
if(user.session != null)
{
//includeFile here
%>
<jsp:include file="header.jsp" />
<%
}
%>
Upvotes: 0