• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP method declaration

 
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Could you confirm the answer?
Question:Which of the follwing JSP fragments correctly define a method?
1.
<% public void m1() { ... } %>
2.
<%! public void m1() { ... } %>
3.
<%@ public void m1() { ... } %>
4.
<%! public void m1() { ... }; %>
5.
<% public void m1() { ... }; %>
Answer: 2 & 4
Isn't 2 a wrong answer since each variable declaration statement must be terminated with a semicolon.
Thanks
Ravi
 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answer 2 & 4 are correct.
Isn't 2 a wrong answer since each variable declaration statement must be terminated with a semicolon.
This is a declaration, but it is not a "variable" declaration. You are just declaring a *method*. All things that are going inside a scriptlet will go in _jspService() method, so you cannot declare your own methods there (you can't declare a method inside a method). So you use a declaration <%! for that.
So you're right, *variable* declarations must end with semicolon. There's no restriction form *method* declarations.
hope it helps
 
ravi janap
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Andres
Thanks for the explanation. I guess the option (2) is more appropriate but having the additional semicolon in (4) does no harm either.
-- Ravi
 
No one can make you feel inferior without your consent - Eleanor Roosevelt. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic