===============================================================================
MCQ QUIZ - TOPIC 2: JSP (STAGE 2)
100 Hours Java Backend Developer Pedagogy
===============================================================================
Instructions:
- Total 80 questions (10 questions for each of the 8 sessions).
- Choose the best option (a, b, c or d) for each question.
- Answers are given in the ANSWER SHEET at the end of this file.
===============================================================================
===============================================================================
SESSION 1 - ELEMENTS AND DIRECTIVES
===============================================================================
Q1. The three JSP scripting elements are:
a) directive, action, expression
b) scriptlet tag, expression tag, declaration tag
c) scriptlet, include, forward
d) page, include, taglib
Q2. The syntax of the JSP scriptlet tag is:
a) <% java source code %>
b) <%= statement %>
c) <%! declaration %>
d) <%@ directive attribute="value" %>
Q3. The JSP expression tag:
a) declares fields and methods
b) includes another file
c) writes the value of a variable or method to the output stream, so
you need not write out.print()
d) defines the attributes of the page
Q4. <%! int data=50; %> is an example of:
a) scriptlet tag
b) declaration tag
c) expression tag
d) directive
Q5. The code written inside a JSP declaration tag is placed:
a) inside the service() method of the auto generated servlet
b) inside the browser
c) inside web.xml
d) outside the service() method of the auto generated servlet, so it
doesn't get memory at each request
Q6. How many types of JSP directives are there?
a) 2
b) 4
c) 3
d) 5
Q7. The default value of the contentType attribute of the page directive
is:
a) text/html;charset=ISO-8859-1
b) text/xml
c) application/json
d) text/plain
Q8. If you set <%@ page isThreadSafe="false" %>, the generated servlet:
a) processes requests in parallel
b) implements SingleThreadModel, so the container serializes the
multiple requests
c) is never translated
d) ignores Expression Language
Q9. The include directive includes the original content of the included
resource:
a) at request time, so it is best for dynamic pages
b) only for image files
c) at page translation time (the JSP page is translated only once), so
it is better to include static resources
d) after the response is committed
Q10. Which page directive attribute names another page that handles an
exception occurring in the current page?
a) isErrorPage
b) import
c) buffer
d) errorPage
===============================================================================
SESSION 2 - ACTION ELEMENTS
===============================================================================
Q1. JSP action tags are mainly used to:
a) control the flow between pages and to use Java Beans
b) compile Java classes
c) create database tables
d) style the HTML page
Q2. The jsp:forward action tag:
a) includes the resource and returns to the current page
b) forwards the request and response to another resource
c) redirects the browser with a brand new URL
d) prints a bean property
Q3. The jsp:include action tag includes the resource:
a) at JSP translation time only
b) at server start up only
c) at request time, so it is better for dynamic pages
d) at compile time only
Q4. Which action tag is used to set a parameter while forwarding or
including?
a) jsp:param
b) jsp:plugin
c) jsp:fallback
d) jsp:element
Q5. The default scope of jsp:useBean is:
a) request
b) session
c) application
d) page
Q6. :
a) deletes all the bean properties
b) sets all the values of the incoming request in the bean
c) prints all the bean properties
d) creates a new bean object
Q7. The jsp:plugin action tag is used to:
a) redirect to another page
b) include XML content
c) embed other components (applets) in the JSP file
d) define a page directive
Q8. To reuse a JavaBean across two different requests (process.jsp and
second.jsp opened through a link), the jsp:useBean scope should be
set to:
a) session
b) page
c) request
d) the bean cannot be shared between pages
Q9. Which of the following must a JavaBean follow?
a) public variables and no methods
b) a main method and static fields
c) an entry in web.xml
d) a no-arg constructor, Serializable and getter/setter methods
Q10. The jsp:fallback action tag:
a) prints a message to the server console if the plugin works
b) prints the message if plugins are not working
c) forwards the request
d) sets a bean property
===============================================================================
SESSION 3 - CREATING CUSTOM TAGS
===============================================================================
Q1. The steps to create a custom tag are:
a) create the JSP file only
b) create the TLD file only
c) create the Tag handler class, create the TLD file and create the
JSP file that uses the custom tag
d) create a servlet and map it in web.xml
Q2. The tag handler class in the current date example is created by
inheriting:
a) TagSupport
b) HttpServlet
c) HttpSession
d) Filter
Q3. To write data for the JSP from the tag handler, we use the JspWriter
obtained from:
a) response.getWriter()
b) pageContext.getOut()
c) System.out
d) a FileWriter
Q4. When doStartTag() returns SKIP_BODY:
a) the body of the tag is evaluated again
b) the JSP page is redirected
c) the body content of the tag will not be evaluated
d) an exception is thrown
Q5. The TLD (Tag Library Descriptor) file must be contained inside:
a) the WEB-INF directory
b) the WEB-INF/lib directory
c) the project root folder
d) the src folder
Q6. To iterate the body content of a custom tag, the handler should
override:
a) destroy()
b) init()
c) doEndTag() only
d) doAfterBody() and return the constant EVAL_BODY_AGAIN
Q7. To use a custom tag in a JSP we write:
a) <%@ page import="java.util.Date" %>
b) <%@ taglib uri="WEB-INF/mytags.tld" prefix="m" %>
c) <%@ include file="header.html" %>
d)
Q8. To define an attribute (e.g. number) for a custom tag you must:
a) only write the attribute in the JSP file
b) do nothing - attributes work automatically
c) define the property with its setter method in the TagHandler class
and define the element inside in the TLD file
d) declare the attribute in web.xml under
Q9. When a custom URI is used in the taglib directive, the web container
gets the information about the TLD file from:
a) the entry (taglib-uri and taglib-location) in
web.xml
b) server.xml
c) the browser cache
d) the MySQL database
Q10. In MyTagHandler, the pageContext instance used to get the JspWriter
is provided by:
a) the constructor of the JSP page
b) web.xml
c) the browser
d) the TagSupport class by default
===============================================================================
SESSION 4 - USING BEANS
===============================================================================
Q1. A Java Bean should not have:
a) public variables - all the variables should be accessed using the
get/set methods
b) private variables
c) getter methods
d) setter methods
Q2. Which JSP action elements are required to use a Java bean in a JSP
file?
a) jsp:include, jsp:forward, jsp:param
b) jsp:set, jsp:get, jsp:show
c) jsp:useBean, jsp:getProperty, jsp:setProperty
d) jsp:plugin, jsp:fallback, jsp:element
Q3. To load a Java bean inside a JSP we use the basic syntax:
a)
b)
c)
d)
Q4. In the Employee.java example of the session, what is the initial value
of the name property?
a) Durga
b) Kumar
c) Arjun
d) Madhu
Q5. After executing jbeandemo.jsp, the "New Employee details" section
prints the name:
a) Durga
b) Madhu
c) CSE
d) an empty value
Q6. After compiling Employee.java, Employee.class (along with the college
package folder) must be copied to:
a) WEB-INF/lib
b) the project root folder
c) the classes folder inside WEB-INF
d) META-INF
Q7. The URL used to execute the JSP on the Tomcat server is:
a) localhost:8080/jbeandemo.jsp
b) localhost:8080/foldername/jbeandemo.jsp
c) file:///foldername/jbeandemo.jsp
d) localhost:8080/WEB-INF/jbeandemo.jsp
Q8. :
a) sets the name property of the employee bean to "Durga"
b) prints the name property
c) creates a new bean named Durga
d) removes the name property
Q9. In the Calculator bean example, calling obj.cube(5) from calc.jsp
prints:
a) 25
b) 15
c) 5
d) 125
Q10. For a JavaBean property named firstName, the accessor and mutator
methods are:
a) getfirstName() and setfirstname()
b) getFirstName() and setFirstName()
c) firstname() and firstname(String)
d) readFirstName() and writeFirstName()
===============================================================================
SESSION 5 - JSTL INTRODUCTION
===============================================================================
Q1. JSTL stands for:
a) JSP Standard Template Library
b) Java Servlet Type Library
c) JSON Standard Transformation Language
d) Java Source Markup Language
Q2. JSTL allows you to program your JSP pages using:
a) only Java classes
b) database triggers
c) tags rather than the scriptlet code
d) C functions
Q3. To use JSTL you must have a container of at least:
a) JSP 1.1
b) JSP 1.2 (or higher)
c) JSP 0.9
d) Servlet 2.1
Q4. The first installation step for JSTL with Tomcat is to copy the JSTL
JAR files to:
a) Tomcat's lib directory
b) the browser's plug-in folder
c) the JSP page folder
d) the MySQL bin directory
Q5. The JSTL TLD files (files ending with .tld) must be copied to:
a) the Tomcat bin directory
b) WEB-INF/classes
c) the project's src folder
d) the web-inf (WEB-INF) directory of the web application
Q6. In web.xml, the entries added for the tag libraries are:
a) and elements
b) and elements
c) elements with and
d) elements
Q7. How many TLD (tag library) entries are listed in the session's
web.xml example?
a) 4
b) 8
c) 16
d) 2
Q8. Which of the following is NOT one of the JSTL tag library TLDs listed
in the session?
a) beans
b) fmt
c) sql
d) x
Q9. According to the session, embedding actual database commands into a
JSP page is:
a) the recommended best practice for all applications
b) required by the JSP specification
c) generally considered bad programming practice except for very small
web applications
d) not possible with JSTL
Q10. The scriptlet example that counts to ten uses the loop:
a) while (i <= 10)
b) for(int i=1;i<=10;i++)
c)
d) do-while
===============================================================================
SESSION 6 - JSP EXPRESSION LANGUAGE
===============================================================================
Q1. The syntax for the Expression Language (EL) in JSP is:
a) <% statement %>
b) statement
c) ${ expression }
d) <%@ el statement %>
Q2. Expression Language is a newly added feature in which JSP version?
a) JSP 2.0
b) JSP 1.2
c) JSP 3.0
d) JSP 0.9
Q3. ${ param.name } retrieves:
a) the value of a session attribute
b) the single value associated with the request parameter "name"
c) the value of a cookie
d) the value of a header
Q4. ${ paramValues.name } retrieves:
a) the single value of the request parameter
b) always null
c) the header value
d) the array of values associated with the request parameter
Q5. ${ sessionScope.user } fetches the attribute "user" bound to:
a) the page scope
b) the request object
c) the session object
d) the application context
Q6. Which EL implicit object is used to get the value of cookies?
a) cookie
b) cookies
c) requestCookie
d) sessionCookie
Q7. Given a cookie named "name" with value "abhishek", the expression
${ cookie.name.value } prints:
a) the name of the cookie
b) abhishek
c) null
d) nothing - EL cannot access cookies
Q8. According to the precedence of operators in EL, which group has the
HIGHEST precedence?
a) || (or)
b) ?:
c) + and - (binary)
d) [] and ()
Q9. Which of the following is a reserved word in EL?
a) loop
b) foreach
c) print
d) empty
Q10. The EL implicit object initParam is used to:
a) map an initialize parameter
b) set a session attribute
c) forward a request
d) include a file
===============================================================================
SESSION 7 - JSTL TAGS
===============================================================================
Q1. According to this session, JSTL stands for:
a) Java SQL Tag Library
b) Java server pages standard tag library
c) Java Simple Type Library
d) JSON Standard Tag Language
Q2. To use the core tags we define the tag library with:
a) <% prefix="core" uri="core" %>
b)
c) <%@ taglib prefix="c" uri=http://java.sun.com/jsp/jstl/core %>
d) <%@ page import="jstl" %>
Q3. The tag:
a) catches any throwable exception which occurs in the body and shows
it as output (held in the var variable)
b) iterates over a collection
c) redirects to another URL
d) sets a variable in a scope
Q4. The escapeXML attribute of :
a) is ignored by the container
b) is always false
c) escapes only SQL keywords
d) is true if it escapes XML characters, so they are not evaluated as
actual tags
Q5. The output of
is:
a) 1 2 3 4 5 6 7 8 9 10
b) 5 6 7 8 9 10
c) 5 6 7 8 9
d) nothing
Q6. With the code
prints:
a) nothing
b) an error page
c) The count is 100
d) 100
Q7. The tag is used to:
a) redirect the current page to another URL by providing the relative
URL (it supports context relative URLs)
b) include another file
c) catch an exception
d) set a bean property
Q8. Which formatting tag handles a date in the various formats?
a)
b)
c)
d)
Q9. To create a user-defined custom tag in the modern style, the tag
handler class must extend SimpleTagSupport and override:
a) service()
b) init()
c) doTag()
d) destroy()
Q10. The TLD file creates a mapping between:
a) the JSP page and the servlet
b) the tag handler class file and the URI mentioned in the TLD file
c) the database and the JSP page
d) the bean and the session
===============================================================================
SESSION 8 - WORKING WITH XML
===============================================================================
Q1. XML stands for:
a) Extensible Markup Language
b) Extra Modern Language
c) Executable Module Language
d) External Mapping Language
Q2. XML is derived from:
a) HTML
b) Standard Generalized Markup Language (SGML)
c) CSS
d) SQL
Q3. XML is used to:
a) display data to the user like HTML
b) compile Java programs
c) carry and transport the data, but not to display the data
d) style web pages
Q4. Which statement about XML versus HTML is correct?
a) XML tags are predefined like HTML tags
b) HTML documents are well-formed, XML documents are not
c) HTML stores and transports data while XML displays it
d) XML tags are user-defined and XML documents are well-formed
Q5. To generate and send an XML document from a JSP, we set:
a) contentType="text/xml" in the page directive
b) import="java.sql" in the page directive
c) buffer="8kb" in the page directive
d) language="xml" in the page directive
Q6. To process XML in a JSP application, which two libraries must be
copied into the "Tomcat Installation Directory/lib" folder?
a) mysql-connector and jstl jar
b) gson and jackson
c) XercesImpl.jar and xalan.jar
d) servlet-api and jsp-api
Q7. XSLT is:
a) XML Storage and Layout Technology
b) Extensible Stylesheet Language Transformation, a transformation
language used for formatting XML
c) XML Syntax Typing Tool
d) a database query language
Q8. Which JSTL XML tag performs the transformation of XML using a
stylesheet?
a)
b)
c)
d)
Q9. In the books.xml document of the session, the root element is:
a)
b)
c)
d)
Q10. "XML documents are plain text and Unicode-based" means:
a) they cannot be edited by tools
b) they must be compiled before use
c) they can be edited and viewed from any simple text editor, take
less space and can be transmitted efficiently
d) they are stored as binary images
===============================================================================
ANSWER SHEET
===============================================================================
SESSION 1 - ELEMENTS AND DIRECTIVES
-------------------------------------------
Q1 : b Q2 : a Q3 : c Q4 : b Q5 : d
Q6 : c Q7 : a Q8 : b Q9 : c Q10 : d
SESSION 2 - ACTION ELEMENTS
-------------------------------------------
Q1 : a Q2 : b Q3 : c Q4 : a Q5 : d
Q6 : b Q7 : c Q8 : a Q9 : d Q10 : b
SESSION 3 - CREATING CUSTOM TAGS
-------------------------------------------
Q1 : c Q2 : a Q3 : b Q4 : c Q5 : a
Q6 : d Q7 : b Q8 : c Q9 : a Q10 : d
SESSION 4 - USING BEANS
-------------------------------------------
Q1 : a Q2 : c Q3 : b Q4 : d Q5 : a
Q6 : c Q7 : b Q8 : a Q9 : d Q10 : b
SESSION 5 - JSTL INTRODUCTION
-------------------------------------------
Q1 : a Q2 : c Q3 : b Q4 : a Q5 : d
Q6 : c Q7 : b Q8 : a Q9 : c Q10 : b
SESSION 6 - JSP EXPRESSION LANGUAGE
-------------------------------------------
Q1 : c Q2 : a Q3 : b Q4 : d Q5 : c
Q6 : a Q7 : b Q8 : d Q9 : d Q10 : a
SESSION 7 - JSTL TAGS
-------------------------------------------
Q1 : b Q2 : c Q3 : a Q4 : d Q5 : b
Q6 : c Q7 : a Q8 : d Q9 : c Q10 : b
SESSION 8 - WORKING WITH XML
-------------------------------------------
Q1 : a Q2 : b Q3 : c Q4 : d Q5 : a
Q6 : c Q7 : b Q8 : d Q9 : a Q10 : c
===============================================================================
END OF QUIZ - 80 QUESTIONS TOTAL
===============================================================================