Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp question

 
Sirisha Gajulapalli
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everyone,
I just started doing the mock exams and i am having difficulty in understanding the answer given for the following question from "Eduardo Cobian's" mock exam.
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.
According to the solution given, it says option 1 is correct. But i thought that jspInit method should always be placed under a declaration.
<% public void jspInit() { ...java code...} %>
As this becomes a scriplet, i thought this would be included under the service method when a servlet is generated and hence will result in an error. so according to me none of the answers are correct.
Please correct me if i am wrong.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The mock exam is wrong. If you put something like this into your JSP
<% public void jspInit() {System.out.print("hello");} %>
you will get a syntax error from the compiler.
 
chi Lin
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron,
thanks for the clarification !!
 
Sirisha Gajulapalli
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Ron.
Siri
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic