• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Rishi Singh
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() { ...java 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!!
 
Carl Trusiak
Sheriff
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() { ...java 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic