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>
– Retrieve a session from “request. getSession(false);”, this function will return a session if existed , else a null value will return. – Later you can do a “null” checking with the session object, null means no existed session available.
Use the getAttribute(String name) or getAttributesNames() methods of the HttpSession object to retrieve attributes that are associated with it. If you want to set a new attribute, or remove an existing one, use setAttribute() and removeAttribute() , respectively.
The session object is used to track a client session between client requests. JSP makes use of the servlet provided HttpSession Interface. This interface provides a way to identify a user across. The JSP engine exposes the HttpSession object to the JSP author through the implicit session object.
<c:if test="${sessionScope.user != null}"> There is a user **attribute** in the session </c:if>
I think you mean checking the session scope right?
<c:if test="${!empty sessionScope.user}">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With