File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes implicit object  in  declaration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "implicit object  in  declaration" Watch "implicit object  in  declaration" New topic
Author

implicit object in declaration

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Jun 06, 2007
Posts: 2716
    
    6

You are violating the language semantics and hence the compiler error.
What's the problem then.


SCJP, SCWCD.
|Asking Good Questions|
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Apr 20, 2006
Posts: 3344

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!


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Thanks Amit,Raghavan and Bear ;)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: implicit object in declaration