Evaluate/Check List/Collection Is Empty In JSTL
Evaluate/Check List/Collection Is Empty In JSTL explains about How to evaluate whether a List or Collection is empty using JSTL empty operator.
Consider the example here, a JSP page which contains a HashMap with lot of key value pairs in it and we need check this list is empty or not
For evaluating a Collection is empty or not inside JSTL, we can use empty operator. By using this operator we can check Collection is empty or not
JSTL Size Of Map
JSTL Size Of Map explains about how to find the size of a map using JSTL Taglib
Consider the example here, a JSP page which contains a HashMap with lot of key value pairs in it and we need to find the size of this HashMap
We already seen how to find the size of a Collection using the JSTL fn:length function.
You can see it fn:length() JSTL Function .
JSTL If Else Example
JSTL If Else Example explains about testing different conditions as per the requirements. It also provides a secondary path (else case) of execution, when an "if" conditions become false.
We have already seen the usage of JSTL If Example
How to use if-else option in JSTL?
There are 2 ways, we can achieve if-else statements using JSTL
1) You can use JSTL C:Choose C:When C:Otherwise Tag
2) You can use JSTL Mod (modulus) operator
You can see the below example, which is demonstrating JSTL If Else Example Using Mod operator
JSTL c:url Example With c:param Tag
JSTL <c:url> tag is used for storing a url into a variable with proper url rewriting, mostly <c:url> is used with <c:param> tag for adding parameter inside a <c:url>.
You can see required attributes for <c:url> and <c:param> tags on the below example.
<c:url> With Request scope
<c:url var="url" value="/index.jsp" context="/JSTLExample" scope="request"/>
${requestScope.url}
<c:url> With Session scope
<c:url var="url" value="/index.jsp" context="/JSTLExample" scope="session"/>
${sessionScope.url}
Get context Path Using JSTL
Get context Path Using JSTL explains about how to get context path inside a JSP page
pageContext is an implicit object available in JSP, so it is very easy to get the contextPath using JSTL EL Expression
You can access the request scoped varaibles in following different ways
Below code is equivalent to <%=request.getContextPath()%> in JSTL?
<c:out value="${pageContext.request.contextPath}"/>
you can see the below a complete example about accessing contextpath in JSTL
Reading Request Attributes Using JSTL
Reading Request Attributes Using JSTL explains about how to access JSTL's request scoped attributes such as variables inside a JSP page
request is an implicit object available in JSP, so it is very easy to access the request scoped varaibles inside JSP page
You can access the request scoped varaibles in following different ways
<c:out value='${requestScope["variableName"]}'/>
<c:out value='${requestScope.variableName}'/>
you can see the below example demonstrating how to access request scoped attributes in JSTL EL expression
Reading Session Attributes Using JSTL
Reading Session Attributes Using JSTL explains about how to access JSTL's session scoped attributes such as variables inside a JSP page
session is an implicit object available in JSP, so it is very easy to access the session scoped varaibles inside JSP page
You can access the session scoped varaibles in following different ways
<c:out value='${sessionScope["variableName"]}'/>
<c:out value='${sessionScope.variableName}'/>
you can see the below complete example demonstrating how to access session scoped attributes in JSTL EL expression
JSP trimDirectiveWhitespaces Example
JSP trimDirectiveWhitespaces Example explains about how to remove unwanted white spaces from your JSP responses
trimDirectiveWhitespaces is new feature available on JSP verion 2.1, as before we can't able to eliminate unwanted white spaces
By using this feature you can have a complete control on your JSP pages and you can trim down the JSP response by removing the white spaces
Below example, I am showing how to trim down a JSP page using trimDirectiveWhitespaces page directive tag
For this, I am creating a simple JSP page and adding trimDirectiveWhitespaces = "true" as a page directive attribute (see the JSP page)