Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

jspInit() in a scriptlet !!! will this work!!!

Ranch Hand
Posts: 321
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given the following jsp line select the correct statements:
<% public void jspInit() { code...} %>
1) It is a valid line that can be used to initialize the servlet that implements the jsp file.
2) It won't compile as no identifer can start with jsp not _jsp.
3) It will serve as the servlet initialization if the function's name is _jspInit.
4) There is no way to initialize a jsp's implementation class servlet.
Whether this wd compile as anything which is there in a scriptlet goes into the service() , I think since this is an scriptlet which is invoked only at request processing time...there wd be a runtime exception..what do u guys say!!
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This will fail to compile. You cannot define methods in scriptlets. Methods must be defined in declarations. If you really mean <%! public void jspInit() { code...} %>
Then the real answer is 1. From JSP 1.2 FCS
"The contract also describes how a JSP author can indicate what actions will be taken when the init() and destroy() methods of the page implementation occur. In JSP 1.2 this is done by defining methods with names jspInit() and jspDestroy() in a declaration scripting element in the JSP page. The jspInit() method, if present, will be called to prepare the page before the first request is delivered. Similarly a JSP container can reclaim resources used by a JSP page when a request is not being serviced by the JSP page by invoking its jspDestroy() method, if present."
I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic