Advanced 250+ TOP MCQs on JSP and Answers

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

1. Which page directive should be used in JSP to generate a PDF page?
a) contentType
b) generatePdf
c) typePDF
d) contentPDF

Answer: a
Clarification: <%page contentType=”application/pdf”> tag is used in JSP to generate PDF.

2. Which tag should be used to pass information from JSP to included JSP?
a) Using <%jsp:page> tag
b) Using <%jsp:param> tag
c) Using <%jsp:import> tag
d) Using <%jsp:useBean> tag

Answer: a
Clarification: <%jsp:param> tag is used to pass information from JSP to included JSP.

3. Application is instance of which class?
a) javax.servlet.Application
b) javax.servlet.HttpContext
c) javax.servlet.Context
d) javax.servlet.ServletContext

Answer: d
Clarification: Application object is wrapper around the ServletContext object and it is an instance of a javax.servlet.ServletContext object.

4. _jspService() method of HttpJspPage class should not be overridden.
a) True
b) False

Answer: a
Clarification: _jspService() method is created by JSP container. Hence, it should not be overridden.

5. Which option is true about session scope?
a) Objects are accessible only from the page in which they are created
b) Objects are accessible only from the pages which are in same session
c) Objects are accessible only from the pages which are processing the same request
d) Objects are accessible only from the pages which reside in same application

Answer: b
Clarification: Object data is available till session is alive.

6. Default value of autoFlush attribute is?
a) true
b) false

Answer: a
Clarification: Default value “true” depicts automatic buffer flushing.

7. Which one is the correct order of phases in JSP life cycle?
a) Initialization, Cleanup, Compilation, Execution
b) Initialization, Compilation, Cleanup, Execution
c) Compilation, Initialization, Execution, Cleanup
d) Cleanup, Compilation, Initialization, Execution

Answer: c
Clarification: The correct order is Compilation, Initialization, Execution, Cleanup.

8. “request” is instance of which one of the following classes?
a) Request
b) HttpRequest
c) HttpServletRequest
d) ServletRequest

Answer: c
Clarification: request is object of HttpServletRequest.

9. Which is not a directive?
a) include
b) page
c) export
d) useBean

Answer: c
Clarification: Export is not a directive.

10. Which is mandatory in tag?
a) id, class
b) id, type
c) type, property
d) type,id

Answer: a
Clarification: The useBean searches existing object and if not found creates an object using class.

Leave a Reply

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