• Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp global variable declaration  RSS feed

 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%! int value = request.getParameter("a1"); %>
it shows can not resolve symbol request. Why ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!