Web / JSP interview questions
Use the fn:contains() or fn:containsIgnoreCase() function.
<c:forEach items="${cartItems}" var="eachItem"> <c:if test="${not fn:containsIgnoreCase(eachItem, 'egg')}"> <p> ${eachItem} doesn't contain 'Egg'</p> </c:if> </c:forEach>
<c:if> tag does not have else tag. So we can use <c:choose> as illustrated below for if-else if- else scenario.
<c:choose> <c:when test="${condition1}"> ... </c:when> <c:when test="${condition2}"> ... </c:when> <c:otherwise> ... </c:otherwise> </c:choose>
JSTL functions library (fn) could be used to find the size or compare size of the collection. for e.g.
<c:if test="${fn:length(listItems) gt 0}"> <p>Items found.</p> </c:if>
Using the below scriptlet in JSP, the session attributes can be accessed.
<%=request.getSession().getAttribute("sessionVariable")%>
Also the session attributes could be accessed using JSTL and Expression Language tag as shown below.
<c:out value="${sessionScope.sessionVarible}"/>
or using,
<c:out value="${sessionScope['sessionVariable']}"/>
A Java Server Page (JSP) is a web page that contains two types of text: static data and JSP elements. Static data can be expressed in any text-based format, such as HTML or XML. JSP is a technology that mixes static content with dynamically-generated content.
Yes, the JSP expressions will be resolved.