• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Variables Scope

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you set variables' scope to for eg. page, session, etc. in JSP?
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic