Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In JSP, how can i check, using JSTL, if certain session attribute exists in request?

Tags:

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> 
like image 727
Vladimir Avatar asked Dec 15 '13 16:12

Vladimir


People also ask

How can check session exist or not in JSP?

– 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.

How do I find session attributes?

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.

What is session object in JSP show its use with proper example?

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.


2 Answers

<c:if test="${sessionScope.user != null}">     There is a user **attribute** in the session </c:if> 
like image 126
JB Nizet Avatar answered Sep 19 '22 16:09

JB Nizet


I think you mean checking the session scope right?

<c:if test="${!empty sessionScope.user}"> 
like image 42
TheDude Avatar answered Sep 17 '22 16:09

TheDude