Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp global variable declaration

 
kri shan
Ranch Hand
Posts: 1486
  • 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: 65542
110
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.
 
Do not set lab on fire. Or this tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!