wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes using jsp:setProperty without jsp:useBean 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 "using jsp:setProperty without jsp:useBean" Watch "using jsp:setProperty without jsp:useBean" New topic
Author

using jsp:setProperty without jsp:useBean

Hasnain Javed Khan
Ranch Hand

Joined: Nov 23, 2007
Posts: 73
Hello All,

I was reading the jsp specs and got confused with the following paragraph.


The object named by the name must have been “introduced” to the JSP
processor using either the jsp:useBean action or a custom action with an
associated VariableInfo entry for this name. If the object was not introduced in this
manner, the container implementation is recommended (but not required) to raise
a translation error, since the page implementation is in violation of the
specification.

Note – A consequence of the previous paragraph is that objects that are stored
in, say, the session by a front component are not automatically visible to jsp:set-
Property and jsp:getProperty actions in that page unless a jsp:useBean action, or
some other action, makes them visible.


I tried out an example where in a servlet, I'm setting a request scoped attribute



and in a forwarded JSP (from the same servlet)





Can someone kindly explain why I'm getting the output since the object named by the name -> "person" was "not Introduced" using a jsp:useBean standard action. ?

Have I understood it incorrectly or did something wrong while coding ?

Kind Regards.
Hasnain.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

If the object was not introduced in this manner, the container implementation is recommended (but not required) to raise a translation error, since the page implementation is in violation of the specification.


[My Blog]
All roads lead to JavaRanch
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi, Hasnain.
In the same section, it also defines
If the JSP processor can ascertain that there is an alternate way guaranteed to
access the same object, it can use that information. For example it may use a
scripting variable, but it must guarantee that no intervening code has invalidated
the copy held by the scripting variable. The truth is always the value held by the
pageContext object.


I think, here alterante way also implies to, setting the attribute in servlet.
Hasnain Javed Khan
Ranch Hand

Joined: Nov 23, 2007
Posts: 73
Hi,
Thanks guys for your answers. I played along with the code and found that jsp:setProperty works in the absence of jsp:useBean but jsp:getProperty does not work and results in an error (500 Internal Server error)

The source code generated for the JSP when using jsp:getProperty without jsp:useBean had the following line of code.



The source code generated for the JSP when using jsp:getProperty with jsp:useBean had the following line of code.



for jsp:getProperty, the calls to page context depends if jsp:useBean is used or not

if used - > findAttribute is called on PageContext

if not used -> getAttribute is called on PageContext

The source code generated for the JSP when using jsp:setProperty with or without using jsp:useBean was same and was always findAttribute on PageContext

Note – A consequence of the previous paragraph is that objects that are stored
in, say, the session by a front component are not automatically visible to jsp:set-
Property and jsp:getProperty actions in that page unless a jsp:useBean action, or
some other action, makes them visible.


Well the above seems true for jsp:getProperty but not for jsp:setProperty

Kind regards.
Hasnain.
 
Don't get me started about those stupid light bulbs.
 
subject: using jsp:setProperty without jsp:useBean