Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

implicit object in declaration

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

can we use implicit object in declaration?
-----------------------------------------------------------
for example: <%! session.setAttribute("key","value") %>
-------------------------------------------------------------

i try to do this...but i am getting compilation error.
so can't we access implicit object in declaration?

please can anyone explain me?
[ July 10, 2008: Message edited by: Bear Bibeault ]
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are violating the language semantics and hence the compiler error.
What's the problem then.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amit Ghorpade:
You are violating the language semantics and hence the compiler error.


Hi Amit,

please,can you explain me?

my question is
can i use implicit object inside declaration(<%! %>)?...if no ,what is the reason?
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because the implicit objects are NOT available at the place where your declaration (with the "!") sits in the converted servlet. Have a look at the source code of the equivalent servlet of your JSP!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying to use an implicit object in a declaration is most likely a sign that you are trying to do something you shouldn't be doing there. Declarations are the easiest way to introduce thread-safety issues into your JSP. They should be avoided unless you really know what they are doing and how they work.

In fact, at this point you shouldn't even be using scriptlets and Java code in a JSP, let alone declarations.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Amit,Raghavan and Bear ;)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic