• Post Reply Bookmark Topic Watch Topic
  • New Topic

decalring static varibles in JSP

 
Rauhl Roy
Ranch Hand
Posts: 401
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Can any one tell me is there any way to declare STATIC variables in JSPs?

In Head First Servlets and JSP, it is written that when container translets JSPs into Servlets it automatically creates one static varible and one static method of its own. May I know why it happens like that any technical reasons??

And one more question is why there is any IMPLEMENTS in JSP. If we are in a sitivation where we are to implemet runnable kind of interface in jsp what should we do?

Thanks in advance

Regards,
Rahul Roy.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can declare static variables by placing them in a <%! %> construct, which creates class-level declarations. Be careful doing so, as accidentally creating class-level read/write instance variables in such a construct can introduce thread-safety issues into your JSPs.

In fact, at this stage of the game, unless you are stuck in a pre-JSP 2.0 world, you should be migrating away from using any scriptlet constructs in your pages at all in favor of the JSTL and EL.
[ August 21, 2006: Message edited by: Bear Bibeault ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!