Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Global variables

 
aakash bhatt
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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 ]
 
boyet silverio
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
boyet silverio
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how did you not get an error there, aakash, when you declared a variable twice in the same scope?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic