GeekInterview.com
Series: Subject: Topic:
Question: 31 of 398

What is the different between _jspInit() and jspInit()?

Asked by: Interview Candidate | Asked on: Nov 21st, 2007
Showing Answers 1 - 11 of 11 Answers
gaurav0252

Answered On : Nov 23rd, 2007

When a JSP page transalated into a Servlet then jspInit() method is converted to _jspInit(). We can override _jspInit() and _jspDestry() but we can't override _jspService() method.

  
Login to rate this answer.
gaurav0252

Answered On : Nov 23rd, 2007

View all answers by gaurav0252

When a JSP page transalated into a Servlet then jspInit() method is converted to _jspInit(). We can override _jspInit() and _jspDestry() but we can't override _jspService() method.

  
Login to rate this answer.
vishnu.baji

Answered On : Feb 28th, 2008

View all answers by vishnu.baji

I dont know the difference between _jspinit() and jspInit() but jspInit() is not converted as _jspInit()... I have checked in the genereated java file it is the same jspInit() name I observed....

Yes  1 User has rated as useful.
  
Login to rate this answer.
manishmca04

Answered On : Apr 15th, 2008

View all answers by manishmca04

I dont know

  
Login to rate this answer.

the jspinit after  converted to servlet will be converterd to _jspinit

Yes  2 Users have rated as useful.
  
Login to rate this answer.

There is no_jspinit() in generated servlet

Yes  2 Users have rated as useful.
  
Login to rate this answer.
pradeepkmr18

Answered On : Jun 11th, 2008

View all answers by pradeepkmr18

There is no _jspInit() ..Underscore is the symbol which says we cannot OverrrideThe life cycle methods are                   jspInit()   we can override_jspService()  we cannot overridejspDestroy()    we can override                                  

Yes  1 User has rated as useful.
  
Login to rate this answer.
ofdrm

Answered On : Aug 20th, 2008

View all answers by ofdrm

All those who say 'There is no_jspinit() in generated servlet'.... are wrong....As of servlets spec 2.4, this method is generated by the container if any custom tags are used in the JSP. Otherwise it doesn't.We can override jspInit()... in that case both th methods will be there, but that will not exactly be an override as _jspInit() will take precedence and be used for initialization.if we try to override _jspInit() and using custom tags, container will throw compilation error saying -duplicate methods. (there will be two _jspInit() methods with same signature)Similarly we can mention our own jspSerivce() method, but that will be of no use (even though in translated java file it will be there).The difference between overriding jspInit() and jspService() is that  - _jspService() will always be there in any JSP->java file and will take precedence and our jspService() method will not be used ever.But _jspInit() method appears in jsp->java file conditionally. so, our jspInit() method will be invoked when there is no _jspInit() method and this is quite possible.Example:-Here is the jsp file code I tested... (I'm not putting the java file code as it is lengthy... but the jsp got translated and compiled without any error and our jspService() method was not used).

  
Login to rate this answer.
Karuna Reddy

Answered On : Aug 22nd, 2008

View all answers by Karuna Reddy

In JSP we have a life cycle methods like jspInit(), and jspDestroy() and _ JspService() methods but there is no sense if u write in ur jsp as _jspInint(), but u can write

  
Login to rate this answer.
shunmugababu

Answered On : Nov 26th, 2008

View all answers by shunmugababu

You cannot override _jspInit() whereas it is possible to override jspInit().

  
Login to rate this answer.

Here is the skeleton of HttpJspBase class which is developed by tomcat developers.You might have a clue from this for all related answers. public abstract class HttpJspBase extends HttpServlet { /*following methods are final*/ static  { // some clases are loaded in this section } @Override final public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException { _jspService(arg0, arg1); } @Override final public void init() throws ServletException { super.init(); jspInit(); _jspInit(); } @Override final public void destroy() { // TODO Auto-generated method stub jspDestroy(); _jspDestroy(); } /*following is implemented by the container during transformation stage*/ abstract void _jspService(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException; /*following are exposed to developer and are empty by default*/ public void jspInit(){} public void jspDestroy(){} public void _jspInit(){} public void _jspDestroy(){} }

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.