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
posted
0
"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
posted
0
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
posted
0
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
posted
0
how did you not get an error there, aakash, when you declared a variable twice in the same scope?