MY mENU


Wednesday 21 March 2012

JSP Interview Questions-part2

 Explain the life-cycle mehtods in JSP?

The jspInit()- The container calls the jspInit() to initialize the servlet instance. It is called before any other method, and is called only once for a servlet instance. 


The _jspservice()- The container calls the _jspservice() for each request, passing it the request and the response objects. 



The jspDestroy()- The container calls this when it decides take the instance out of service. It is the last method called n the servlet instance.



What JSP lifecycle methods can I override?
We can override jspInit() and jspDestroy() methods but we cannot override _jspService() method.



How can I override the jspInit() and jspDestroy() methods within a JSP page?
By using JSP declation tag



<%! 
        public void jspInit() {
                . . .
        }
%>
<%!     
        public void jspDestroy() {
                . . .   
        }
%>



 Explain about translation and execution of Java Server pages?

A java server page is executed within a Java container. A Java container converts a Java file into a servlet. Conversion happens only once when the application is deployed onto the web server. During the process of compilation Java compiler checks for modifications if any modifications are present it would modify and then execute it.

Why is _jspService() method starting with an '_' while other life cycle methods do not?
_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.

No comments:

Post a Comment