In JSP, how can i check, using JSTL, if certain se

2019-03-12 09:20发布

问题:

This is code in servlet:

HttpSession session = request.getSession(true);
session.setAttribute("user", user);

I am forwarding request to JSP, where i want to check if there is session scoped user parameter attached.

<c:if test="${??? - check if user is attached to request}">
/   /message
</c:if>

回答1:

<c:if test="${sessionScope.user != null}">
    There is a user **attribute** in the session
</c:if>


回答2:

I think you mean checking the session scope right?

<c:if test="${!empty sessionScope.user}">


回答3:

you can do that by using the following code

Setting session in Servlet

HttpSession session = request.getSession(); 
session.setAttribute("user", user);

Access session value by EL in JSP

<p>${sessionScope:user}</p>

Checking the session in JSP using JSTL

<c:if test="${sessionScope:user != null}" > 
   session value present......
</c:if>