Set - 3

Question 16 :

Why is _jspService() method starting with an '_' while other life cycle methods do not?

Answer :

_jspService() method will be written by the container hence any methods which are not to be overridden by the end user are typically written starting with an '_'. This is the reason why we don't override _jspService() method in any JSP page.


Question 17 :

What happens when a page is statically included in another JSP page?

Answer :

An include directive tells the JSP engine to include the contents of another file (HTML, JSP, etc.) in the current page. This process of including a file is also called as static include.


Question 18 :

A JSP page, include.jsp, has a instance variable "int a", now this page is statically included in another JSP page, index.jsp, which has a instance variable "int a" declared. What

Answer :

happens when the index.jsp page is requested by the client?
Compilation error, as two variables with same name can't be declared. This happens because, when a page is included statically, entire code of included page becomes part of the new page. at this time there are two declarations of variable 'a'. Hence compilation error.


Question 19 :

Can you override jspInit() method? If yes, In which cases?

Answer :

ye, we can. We do it usually when we need to initialize any members which are to be available for a servlet/JSP throughout its lifetime.