• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp global variable declaration

 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<%! int value = request.getParameter("a1"); %>
it shows can not resolve symbol request. Why ?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Big mistake. BIG mistake. HUGE!

Firstly, the symbol request cannot be resolved because it is an implicit variable only available to the body (service() method to be specific) of the JSP.

Secondly, creating declarations like this destroys the thread-safety of your JSP. Since the declaration creates an instance variable, and there is only one instance of the servlet created on behalf of the JSP, every single request for the JSP will share the value of the variable. Obviously not a good thing!
[ February 14, 2006: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot use the request object in a declaration.
Use <% String value = request.getParameter("a1"); %> instead.

Note that getParameter() returns a String.
You'll have to convert it to an int.
reply
    Bookmark Topic Watch Topic
  • New Topic