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.

12 Questions Published

Questions

Question 1 Multiple Choice (Multiple Answers)

What is the effect of evaluation of following expression? Select the one correct answer. ${(5*5) ne 25}

  1. true
  2. false
  3. 25
  4. The expression does not compile as ne is not a valid operator.
Question 2 Multiple Choice (Multiple Answers)

What is the effect of evaluation of following expression? Select the one correct answer. ${'cat' gt 'cap'}

  1. true
  2. false
  3. catcap
  4. The expression does not compile as gt operator cannot be applied on strings.
Question 3 Multiple Choice (Multiple Answers)

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. 1
  2. 5
  3. 6
  4. 11
Question 4 Multiple Choice (Multiple Answers)

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" %>

  1. <c:set var="item" value="2"/>
  2. <c:if test="${var==1}" var="result" scope="session">
  3. <c:out value="${result}"/>
  4. </c:if>
Question 5 Multiple Choice (Multiple Answers)

The JSTL code does not compile as attribute for if tag are not correct.

  1. true
  2. false
  3. Nothing gets printed.
  4. Error message printed
Question 6 Multiple Choice (Multiple Answers)

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"/>

  1. The JSTL code does not compile as an attribute for forEach tag is not correct.
  2. 0
  3. 2
  4. ABC
  5. Nothing gets printed as c.out statement does not get executed.
Question 7 Multiple Choice (Multiple Answers)

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"/>

  1. No number gets printed.
  2. One number gets printed.
  3. Two numbers gets printed.
  4. Three numbers gets printed.
  5. Four numbers gets printed.
Question 8 Multiple Choice (Multiple Answers)

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. 1
  2. 2
  3. 3
  4. 4
  5. abc
Question 9 Multiple Choice (Multiple Answers)

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"/>

  1. 2
  2. 3
  3. 4
  4. abc
Question 10 Multiple Choice (Multiple Answers)

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. 1
  2. 2
  3. 3
  4. 4
  5. abc
Question 11 Multiple Choice (Multiple Answers)

Which of these represent the correct path for the core JSTL library in JSTL version 1.1? Select the one correct answer.

  1. http://java.sun.com/jsp/jstl/core
  2. http://java.sun.com/jsp/core
  3. http://java.sun.com/core
  4. http://java.sun.com/jsp/jstl1.1/core
Question 12 Multiple Choice (Multiple Answers)

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.

  1. tagname
  2. name
  3. tag
  4. prefix