Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

does JSP declaration require ; semicolon??

 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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() { ... }; %>


Given answers is 2, 4.

Both option uses JSP declaration to define a methos but one of them is without semicolon.
Dose semicoln is not required in declaration OR extra semicolon is OK??? (I got this question from enthuware)


Thnaks
 
Rob Spoor
Sheriff
Pie
Posts: 20751
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP declarations are just like regular declarations. Fields require a ; at the end, whereas methods can have them.
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if don't provide the semicolon?? Is it leads to some error in JSP declaration block?
 
Rob Spoor
Sheriff
Pie
Posts: 20751
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not if you omit it after a method.

<%! public void m1() { ... }; %> will be translated in a method declaration, 100% similar as in the following example class:

And you don't need a semi colon after that method declaration, now do you?
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob,

means there is no requirement of putting semicolon in declaration block in JSP but if you do so there won't be any error.. so you can simply omit it

Am I right??
 
Rob Spoor
Sheriff
Pie
Posts: 20751
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For methods yes. You only need semi colons in field declarations:
<%! public int x; %>
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Budy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic