Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Declarations

 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the difference between
<% int x = 44; %>
and

<%! int x = 44; %>
Is one a local variable and the other is not?
Thanks,
Drew
 
g madhava
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<% int x = 44; %>
==> This goes in to the _jspService() method
something like this,[which is effectively a local variable]
public void _jspService()
{
int x = 44;
}
and
<%! int x = 44; %>
goes into the instance declaration. So this is a class level variable.
 
Mark Stein
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, technically one is a local varible, and one is not, but you need to know more.
Declarations (<%! int x = 44; %> are initialized only once, when the page is first loaded. They are outside the jsp service method, so you can also declare a method using the <%! %> tag.
<% int x = 44; %> is a scriptlet. What you've done is declare a local variable that will be called in the jsp service method each time the page is called.
I suggest you read up on the different jsp tags, Declarations, Scriptlets, and Page Directives, and also the jsp life cycle. It'll help you understand things a little better, plus both are important for the test.
MS
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic