Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

jspInit()

 
Ranch Hand
Posts: 579
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to ask whether jspInit() is called from within init() or init(ServletConfig) ?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jspInit is called by the container
 
agrah upadhyay
Ranch Hand
Posts: 579
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure Satou?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP spec, JSP.11.2.1 API Contracts

- Methods the JSP Container Invokes : void jspInit()
- Comments: Method is optionally defined in JSP page. Method is invoked when the JSP page is initialized. When method is called all the methods in servlet, including getServletConfig are available

Where else do you think it would be called ?
 
agrah upadhyay
Ranch Hand
Posts: 579
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But JSP is converted ultimately into a servlet and then init() method of this servlet is called from where jspInit() is called.........I think
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I want to ask whether jspInit() is called from within init() or init(ServletConfig) ?



If you are working in servlets and like to override the init() method you should always override the no-args init() method. Since init(ServletConfig) will directly be called by the container. If you happen to override init(ServletConfig) then you should always make a call to super.init(ServletConfig).

Yes jspInit() method will be called by the container as this page's life as a servlet. It is called from servlet's init(ServletConfig)[by the container by default], so by the time this method runs there is a servletconfig and sevletcontext available to the servlet generated from jsp page.

If you have HFSJ book check page: 308
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vishnu is right.
HttpJspBase extends HttpServlet and jspInit() is called in init(ServletConfig ).
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satou kurinosuke has explained with respect to apache tomcat


servlet generated from a JspOne.jsp page
public final class JspOne_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {



Let me explain the general scenario

When you use a jsp page for the first time after it has been deployed in a server it will be translated into java source code and compiled in to servlet class file by the container and that servlet will implement HttpJspPage.

HttpJspPage interface defines the life cycle method _jspService(HttpServletRequest request, HttpServletResponse response) and extends Servlet interface and JspPage interface in which life cycle methods jspInit() & jspDestroy() are defined. JspPage interface extends Servlet interface which defines init(ServletConfig config) method.
 
    Bookmark Topic Watch Topic
  • New Topic