Advanced 250+ TOP MCQs on JSP Elements and Answers

This set of Advanced Java Multiple Choice Questions & Answers (MCQs) on “JSP Elements”.

1. Which one of the following is correct for directive in JSP?
a) <%@directive%>
b) <%!directive%>
c) <%directive%>
d) <%=directive%>

Answer: a
Clarification: Directive is declared as <%@directive%>.

2. Which of the following action variable is used to include a file in JSP?
a) jsp:setProperty
b) jsp:getProperty
c) jsp:include
d) jsp:plugin

Answer: c
Clarification: jsp:include action variable is used to include a file in JSP.

3. Which attribute uniquely identification element?
a) ID
b) Class
c) Name
d) Scope

Answer: a
Clarification: ID attribute is used to uniquely identify action element.

4. “out” is implicit object of which class?
a) javax.servlet.jsp.PrintWriter
b) javax.servlet.jsp.SessionWriter
c) javax.servlet.jsp.SessionPrinter
d) javax.servlet.jsp.JspWriter

Answer: d
Clarification: JspWriter object is referenced by the implicit variable out which is initialized automatically using methods in the PageContext object.

5. Which object stores references to the request and response objects?
a) sessionContext
b) pageContext
c) HttpSession
d) sessionAttribute

Answer: b
Clarification: pageContext object contains information about directives issued to JSP page.

6. What temporarily redirects response to the browser?
a)
b) <%@directive%>
c) response.sendRedirect(URL)
d) response.setRedirect(URL)

Answer: c
Clarification: response.sendRedirect(URL) directs response to the browser and creates a new request.

7. Which tag is used to set a value of a JavaBean?
a)
b)
c)
d)

Answer: a
Clarification: is used to set a value of a java.util.Map object.

8. Can and <%–comment–%> be used alternatively in JSP?
a) True
b) False

Answer: b
Clarification: is an HTML comment. <%–comment–%> is JSP comment.

9. Java code is embedded under which tag in JSP?
a) Declaration
b) Scriptlet
c) Expression
d) Comment

Answer: b
Clarification: Scriptlet is used to embed java code in JSP.

10. Which of the following is not a directive in JSP?
a) page directive
b) include directive
c) taglib directive
d) command directive

Answer: d
Clarification: command directive is not a directive in JSP.

Leave a Reply

Your email address will not be published. Required fields are marked *