Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scope of variables in declarations

 
Ryan Day
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the following in a Struts book that shall remain nameless to protect the guilty:

Similarly, any variables that are defined with a JSP declaration are local to the service( ) method:

<%! String test = "test value"; %>


This doesn't look right to me, don't variables declared in declarations become instance variables?

So what scope would they fall into?
page
request
session
application
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This doesn't look right to me, don't variables declared in declarations become instance variables?

You're right, they become accessible globally to the page. The scope is the page.
 
Krishna Srinivasan
Ranch Hand
Posts: 1876
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%! String test = "test value"; %>


Yes, this become instance varibale for the jsp page. only the variables declared inside scriptlet becomes local variable like :

<%
int i =10;
%>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic