• Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt Reagrding inti() method

 
Akhilesh Yadav
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As we all know every jsp is converted in to servlet

when in write jsp declration tag <%! public void a(){} %>
this will go into init() method of servlet

but when i write Expression <% public void a(){} %>
this will go into service() method of servlet

in expression tag it ie.service() shows error illegal start of expression .....

why it doesnt show in init() method the same error because even init() is a method.
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Akhilesh Yadav]when in write jsp declration tag <%! public void a(){} %>
this will go into init() method of servlet


This would not go into the init() method. This would declare a new method in the servlet.

As method can not contain any other method directly, declaring a method in a <% %> would lead to an error as all the code would be put in the service() method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!