File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes scope of variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "scope of variable" Watch "scope of variable" New topic
Author

scope of variable

Nilesh Srivastava
Ranch Hand

Joined: Aug 29, 2003
Posts: 70
Hi All.
If I declare a variable ina a JSP page, what is the scope of that variable
Thanks
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 641
Nilesh,
If u define variable as
<%
String scope="request";
%>
then it's scope is for request.
and if u define it as
<%!
String scope="Application";
%>
Then this variable is aval till jsp is in memory
Praful


All desirable things in life are either illegal, banned, expensive or married to someone else !!!
Java Brewer
Greenhorn

Joined: Oct 13, 2003
Posts: 5
Hi Nilesh,
You need to learn a bit.. Better say this way

The above variable behaves as a local variable, as it will be
available inside the [B]service()[b] method. You wont
be able to access this variable if you have declared a method
in JSP. where as...

In this case, the variable behaves as a member variable. It will be
available thruout the JSP, and even you can access this variable
in any of you method defined in JSP. It has scope in the JSP in
which it is declared as well as in in the static include files i.e.
include using but not
available to dynamic include i.e. .

I hope this clears the doubt.
Regards
Goodieguy
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Welcome to the Ranch Java Brewer!
You'll find that there aren't many rules you'll have to worry about, but one is that proper names are required. And while yours passes the format check, it fails in the 'obviously fictitious' category. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
Thanks!
bear
JSP Forum Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: scope of variable