aspose file tools*
The moose likes JSP and the fly likes Global variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Global variables" Watch "Global variables" New topic
Author

Global variables

aakash bhatt
Ranch Hand

Joined: Jan 09, 2003
Posts: 182
Hi all,
When I declare this as global it gives me an error where as I do not declare the variable
as gloabl it runs with out error
Error:
<%!
int a = 10;
String a = request.getParameter("name");
%>
<input type=text value = "<%=a%>" >

No Error
<%
int a = 10;
String a = request.getParameter("name");
%>
<input type=text value = "<%=a%>" >
Regards,
Aakash
Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
"request" object is avilable only inside the service and related method like doPost, doGet methods.
When you declare it global(class level) variable. The variable will be out side the service method of jsp. Hence "request" object do not have any value assigned, hence you are getting error.
-arun
[ January 28, 2003: Message edited by: Arun Boraiah ]

Sharing is learning
boyet silverio
Ranch Hand

Joined: Aug 28, 2002
Posts: 173

No Error
<%
int a = 10;
String a = request.getParameter("name");
%>
<input type=text value = "<%=a%>" >

this also has an error because 'a' is declared twice.
[ January 29, 2003: Message edited by: boyet silverio ]
Dharmin Desai
Ranch Hand

Joined: Feb 28, 2002
Posts: 81
Arun is absolutely right.
request is one of the implicit variable.
request object is passed as an argument to _jspService() method by container, when browser requests for a particular JSP.
Whereas u r using request variable at global phase, which is erroe porn.
Hope this helps, Dharmin


SCJP2 (93%),SCWCD(88%)<br />-------------------------------<br />Never under estimate yr self, just represent yr profile in proper manner.
boyet silverio
Ranch Hand

Joined: Aug 28, 2002
Posts: 173
how did you not get an error there, aakash, when you declared a variable twice in the same scope?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Global variables
 
Similar Threads
Problem accessing a bean from a JSP
get.parameter and text box
How to retrive data two times from database in sinble jsp page.
would u like to open the file or save it to your system
Error in request.getParameter