Advanced Java Questions & Answers – JSP Elements

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

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

Answer: a
Explanation: 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
View Answer

Answer: c
Explanation: 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
View Answer

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

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
View Answer

Answer: d
Explanation: 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
View Answer

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

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

Answer: c
Explanation: 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) <c:set>
b) <c:param>
c) <c:choose>
d) <c:forward>
View Answer

Answer: a
Explanation: <c:set> is used to set a value of a java.util.Map object.
advertisement

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

Answer: b
Explanation: <!–comment–> 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
View Answer

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

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

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

Sanfoundry Global Education & Learning Series – Java Programming Language.

To practice all areas of Java language, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.