my dog learned polymorphism*
The moose likes JSP and the fly likes Variables Scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Variables Scope" Watch "Variables Scope" New topic
Author

Variables Scope

amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231
How do you set variables' scope to for eg. page, session, etc. in JSP?
Jason Brawner
Ranch Hand

Joined: Dec 19, 2001
Posts: 66
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


Jason E. Brawner<br />Sun Certified Java Programmer<br />Sun Certified Web Component Developer
Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
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 ]

Sharing is learning
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Variables Scope