JSP and JSTL Programming
Test your knowledge of JavaServer Pages (JSP) and JSP Standard Tag Library (JSTL) including tag libraries, core JSTL tags (c:set, c:forEach, c:if, c:choose, c:out), and expression language.
Questions
What is the effect of evaluation of following expression? Select the one correct answer. ${(5*5) ne 25}
- true
- false
- 25
- The expression does not compile as ne is not a valid operator.
What is the effect of evaluation of following expression? Select the one correct answer. ${'cat' gt 'cap'}
- true
- false
- catcap
- The expression does not compile as gt operator cannot be applied on strings.
How many numbers are printed, when the following JSTL code fragment is executed? Select the one correct answer. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <c:forEach var="item" begin="0" end="10" step="2"> ${item} a)1 b)5 c)6 d)11
- 1
- 5
- 6
- 11
What gets printed when the following JSTL code fragment is executed? Select the one correct answer. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
- <c:set var="item" value="2"/>
- <c:if test="${var==1}" var="result" scope="session">
- <c:out value="${result}"/>
- </c:if>
The JSTL code does not compile as attribute for if tag are not correct.
- true
- false
- Nothing gets printed.
- Error message printed
What gets printed when the following JSTL code fragment is executed? Select the one correct answer. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <c:set var="item" value="2"/> <c:forEach var="item" begin="0" end="0" step="2"> <c:out value="${item}" default="abc"/>
- The JSTL code does not compile as an attribute for forEach tag is not correct.
- 0
- 2
- ABC
- Nothing gets printed as c.out statement does not get executed.
How many numbers gets printed when the following JSTL code fragment is executed? Select the one correct answer. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <c:set var="item" value="2"/> <c:choose> <c:when test="${item>0}"> <c:out value="1"/> <c:when test="${item==2}"> <c:out value="2"/> <c:when test="${item<2}"> <c:out value="3"/> <c:otherwise> <c:out value="4"/>
- No number gets printed.
- One number gets printed.
- Two numbers gets printed.
- Three numbers gets printed.
- Four numbers gets printed.
Which numbers gets printed when the following JSTL code fragment is executed? Select the two correct answers. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <c:set var="j" value="4,3,2,1"/> <c:forEach items="${j}" var="item" begin="1" end="2"> <c:out value="${item}" default="abc"/>
- 1
- 2
- 3
- 4
- abc
Which numbers gets printed when the following JSTL code fragment is executed? Select the two correct answers. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <c:set var="j" value="4,3,2,1"/> <c:forEach items="${j}" var="item" begin="1" end="2" varStatus="status"> <c:out value="${status.count}" default="abc"/>
- 2
- 3
- 4
- abc
Which number gets printed when the following JSTL code fragment is executed? Select the one correct answers. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <c:set var="j" value="4,3,2,1"/> <c:forEach items="${j}" var="item" varStatus="status"> <c:if test="${status.first}"> <c:out value="${status.index}" default="abc"/>
- 1
- 2
- 3
- 4
- abc
Which of these represent the correct path for the core JSTL library in JSTL version 1.1? Select the one correct answer.
- http://java.sun.com/jsp/jstl/core
- http://java.sun.com/jsp/core
- http://java.sun.com/core
- http://java.sun.com/jsp/jstl1.1/core
A JSP file uses a tag as myTaglib:myTag. The myTag element here should be defined in the tag library descriptor file in the tag element using which element. Select the one correct answer.
- tagname
- name
- tag
- prefix