J2EE - Interview Questions and Answers on JSP

Q1.  What is a config Object? 

Ans. The config object is an instantiation of javax.servlet.ServletConfig and is a direct wrapper around the ServletConfig object for the generated servlet. This object allows the JSP programmer access to the Servlet or JSP engine initialization parameters such as the paths or file location.

Q2.  What is a pageContext Object? 

Ans. The pageContext object is an instance of a javax.servlet.jsp.PageContext object. The pageContext object is used to represent the entire JSP page. This object stores references to the request and response objects for each request. The application, config, session, and out objects are derived by accessing attributes of this object.The pageContext object also contains information about the directives issued to the JSP page, including the buffering information, the errorPageURL, and page scope.

Q3.  What are the phases of the JSP life cycle ?

Ans. 

Translation of JSP Page

Compilation of JSP Page

Classloading (class file is loaded by the classloader)

Instantiation (Object of the Generated Servlet is created).

Initialization ( jspInit() method is invoked by the container).

Reqeust processing ( _jspService() method is invoked by the container).

Destroy ( jspDestroy() method is invoked by the container).


Q4.  Difference between the jsp scriptlet tag and jsp declaration tag?

Ans. The jsp scriptlet tag can only declare variables not methods whereas jsp declaration tag can declare
variables as well as methods.

The declaration of scriptlet tag is placed inside the _jspService() method whereas The declaration of jsp declaration tag is placed outside the _jspService() method.

Q5.  What are JSP directives ? What are different types of directives ?

Ans. The jsp directives are messages that tells the web container how to translate a JSP page into the corresponding servlet.

There are three types of directives -

• page directive
• include directive
• taglib directive