Collection of frequently asked interview questions from JSP. There are more than 15 interview questions and the answers are also provided in detail. Hope these questions will be of help to you.
A JSP is a technology that combines HTML/XML markup languages and elements of Java programming Language to return dynamic content to the Web client, It is normally used to handle Presentation logic of a web application, although it may have business logic.
JSP is usually used for presentation in the MVC pattern (Model View Controller) i.e. it plays the role of the view. The controller deals with calling the model and the business classes which in turn get the data, this data are then presented to the JSP for rendering on to the client.
Normally a Jsp page is similar to a HTML page but it is actually a servlet.
The JSP engine does under go thru different phases before disposing it. There are essentially 7 phases.
Page translation: -page is parsed, and a java file which is a servlet is created.
Page compilation: page is compiled into a class file
Page loading : This class file is loaded.
Create an instance :- Instance of servlet is created
jspInit() method is called
_jspService is called to handle service calls
_jspDestroy is called to destroy it when the servlet is not required.
JSP has the capability to include other HTML and JSP file in one JSP file. This feature is normally encompassed using the ‘include’ directive. When the JSP engine is presented with such a JSP page it is converted to one servlet class and this is called a translation unit, Things to remember in a translation unit is that page directives affect the whole unit, one variable declaration cannot occur in the same unit more than once, the standard action jsp:useBean cannot declare the same bean twice in one unit.
The initialization parameters are the parameters required for the whole of application and not pertaining to any JSP or Servlet. Normally these Context initialization parameters will be mentioned in the web.xml file.