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

JSP implicit objects

Steven Colley
Ranch Hand

Joined: Feb 18, 2005
Posts: 290
Hi, again

For instance:

1- <c:set var="pageContext" value="XXX" scope="page" />
or..
2- <% pageContext.setAttribute("out", "outString" , PageContext.PAGE_SCOPE); %>

3- <% pageContext.setAttribute("exception", "exceptionString" , PageContext.PAGE_SCOPE); %>

4- <%pageContext.setAttribute("page", "pageString" , PageContext.PAGE_SCOPE); %>

Does it overwrite the original implicit objects (in page scope)? or is it a translation error???

Tks.


SCJP | SCWCD | SCBCD | SCWSD 5 | SCEA (I) 1.4 | SCEA 5 | IBM SOA 669
shweta bulbule
Ranch Hand

Joined: Mar 24, 2006
Posts: 30
i guess a translation error, coz i don't think weblogic gives u right to play with implicit objects like this.
sorry no solid explanation though.


Thanks,<br />Shweta
shweta bulbule
Ranch Hand

Joined: Mar 24, 2006
Posts: 30
ooops sorry weblogic=jsp
Rodrigo Alvarez
Ranch Hand

Joined: Apr 10, 2006
Posts: 75
Hi all,


I don't think this would lead to an error. Implicit object are not attribute of the pageContext, they just are object that have "naming resolution priority" (please forgive my foreign's English ) against attribute of the pageContext.

Here's what I found in the JSP spec:




=> it looks legal to do a



, only a



would still resolve to the implecit object exception and



would be the attribute.


It is a mistake to think you can solve any major problems just with potatoes.<br />--Douglas Adams
Steven Colley
Ranch Hand

Joined: Feb 18, 2005
Posts: 290
HI all,

[/QB]
JSP.2.10 Implicit Objects
The EL defines a set of implicit objects which depends on the context in which the EL is being used. When an expression references one of these objects by name, the appropriate object is returned instead of the corresponding attribute. For example in the context of JSP pages, ${pageContext} returns the PageContext object, even if there is an existing pageContext attribute containing some other value.The following implicit objects are available to EL expressions used in JSP
[/QB]


Hi Simon,

You said : "Implicit object are not attribute of the pageContext"..

OK, but i�m not talking about EL issues.
I agree with you. For instance:
We could have this:

EL: {applicationScope.something} , and
PageContext: pageContext.getServletContext()


Originally posted by Felipe Pittella:
Hi, again

For instance:

1- <c:set var="pageContext" value="XXX" scope="page" />
or..
2- <% pageContext.setAttribute("out", "outString" , PageContext.PAGE_SCOPE); %>

3- <% pageContext.setAttribute("exception", "exceptionString" , PageContext.PAGE_SCOPE); %>

4- <%pageContext.setAttribute("page", "pageString" , PageContext.PAGE_SCOPE); %>

Does it overwrite the original implicit objects (in page scope)? or is it a translation error???

Tks.


But the problem for me is..(what i still dindpt figure out..)

--> "outString", "exceptionString" and "pageString" are all "PAGE" scoped attributes, as well as the other implicit ones such as out, exception and page..IN THE SME JSP pagein this case.

What dind�t i figure out?

Tks so much
Rodrigo Alvarez
Ranch Hand

Joined: Apr 10, 2006
Posts: 75
Hi Felipe;



are all "PAGE" scoped attributes, as well as the other implicit ones such as out, exception and page..IN THE SME JSP pagein this case.


I don't think so. The implicit objects such as out, exception and page are not page scope attributes, they are local variables in the Java translated code. When the JSP file is translated, it ends up as a servlet-like (or maybe it is a servlet, I'm not sure) which declares the implicit objects as local variables of the processing method ( service() ) : the JSP code gives something like :



=> I guess if you refer to out in some JSP code, the translator translates that into a reference to the JspWriter out; above and if you refer to some other attribute you end up with a runtime methode looking for it in every scope. Or maybe it all happens in runtime. In any case I don't think it is a problem to have a page scope attibute with the same name as an implicit object.
[ April 15, 2006: Message edited by: Simon Alvarez ]
Steven Colley
Ranch Hand

Joined: Feb 18, 2005
Posts: 290
Hi Simon, yes, i guess y�re right.

As far this.."it ends up as a servlet-like (or maybe it is a servlet, I'm not sure)"..Yes, the container works with the Servlet class. Each Engine has its own mechanism to generate the Servlet class in accordance the spec.

And another thing, i got this from a mock:

"pageContext" is also the name of an implicit object, the expression ${pageContext} will evaulate to that object. Therefore, it is not recommended to use names of impicit objects as regular attributes.".

Tks.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JSP implicit objects