GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  J2EE  >  JSP
Go To First  |  Previous Question  |  Next Question 
 JSP  |  Question 302 of 306    Print  
What is the different between _jspInit() and jspInit()?

  
Total Answers and Comments: 10 Last Update: November 26, 2008     Asked by: d 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: sriharshanamala
 

the jspinit after  converted to servlet will be converterd to _jspinit



Above answer was rated as good by the following members:
pinky_jain1611, pradeepkmr18
November 23, 2007 01:39:31   #1  
gaurav0252        

RE: What is the different between _jspInit() and jspIn...
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.
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
November 23, 2007 01:41:44   #2  
gaurav0252 Member Since: June 2007   Contribution: 9    

RE: What is the different between _jspInit() and jspIn...
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.
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
February 28, 2008 07:07:29   #3  
vishnu.baji Member Since: February 2008   Contribution: 3    

RE: What is the different between _jspInit() and jspInit()?
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....
 
Is this answer useful? Yes | No
April 15, 2008 01:39:05   #4  
manishmca04 Member Since: April 2008   Contribution: 1    

RE: What is the different between _jspInit() and jspInit()?
i dont know
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
May 05, 2008 00:47:12   #5  
sriharshanamala Member Since: February 2008   Contribution: 5    

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

the jspinit after  converted to servlet will be converterd to _jspinit


 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 1Overall Rating: +1    
May 07, 2008 10:24:39   #6  
vanammadhav123 Member Since: January 2007   Contribution: 1    

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

There is no_jspinit() in generated servlet


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 1Overall Rating: -N/A-    
June 11, 2008 03:44:44   #7  
pradeepkmr18 Member Since: June 2008   Contribution: 25    

RE: What is the different between _jspInit() and jspInit()?
there is no _jspInit() ..

Underscore is the symbol which says we cannot Overrride

The life cycle methods are
                  
jspInit()   we can override

_jspService()  we cannot override

jspDestroy()    we can override
           
                       

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
August 20, 2008 02:01:18   #8  
ofdrm Member Since: August 2008   Contribution: 2    

RE: What is the different between _jspInit() and jspInit()?
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).

<!doctype html public "-//w3c//dtd html 4.0 transitional//en" "http://www.w3.org/TR/REC-html40/strict.dtd">
<%@ page session="false" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<c:set var="drm" value="ddd" />
<%!
    public void jspInit() {
    }

    /* --duplicate method error
    public void _jspInit() {
    }*/

    public void jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {
            JspWriter out = JspFactory.getDefaultFactory().getPageContext(this, request, response,
                  null, false, 8192, true).getOut();

            out.write("<!doctype html public "-//w3c//dtd html 4.0 transitional//en" "http://www.w3.org/TR/REC-html40/strict.dtd">rn");
            out.write("rn");
            out.write("rn");
             out.write('r');
          out.write('n');
          out.write("rn");
          out.write("sss");
    }
%>
ddd

 
Is this answer useful? Yes | No
August 22, 2008 07:49:56   #9  
Karuna Reddy Member Since: June 2007   Contribution: 40    

RE: What is the different between _jspInit() and jspInit()?
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


 
Is this answer useful? Yes | No
November 26, 2008 03:03:52   #10  
shunmugababu Member Since: November 2008   Contribution: 1    

RE: What is the different between _jspInit() and jspInit()?
You cannot override _jspInit() whereas it is possible to override jspInit().
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape