Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Variables Scope

 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you set variables' scope to for eg. page, session, etc. in JSP?
 
Jason Brawner
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By default, a variables scope is of 'page' if your declaring it in a jsp page (within an scriplet or declaration). If you want the variable to be of scope session, do something like the following...
session.setAttribute(name, value)
Then you can access your variable using session.getAttribute(name);
Hope this helps,
JEB
 
Arun Boraiah
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is just an extension for Jason's explanation.
in jsp if you want class level variable to be declared then use <%! %> (declaration tag) to declare . Other variable i.e, declared
in scriplet tag will be availabe to service method. Even you can define user defined method level variable with in declaration tag
has explained below
<%!
public void testMethod(){// this method can be called by service method
int count;//method level variable have scope with in testMethod()
.....

}
%>
Hope this is usefull
-arun
[ January 25, 2002: Message edited by: arun boraiah ]
 
Forget this weirdo. You guys wanna see something really neat? I just have to take off my shoe .... (hint: it's a tiny ad)
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!