This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using jsp:setProperty without jsp:useBean

 
Hasnain Javed Khan
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Chinmaya Chowdary
Ranch Hand
Posts: 432
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic