• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

scriptless JSP pages and <useBean> action behavior

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

in Charles Lyons book SCWCD Study Companion, on page 346 there is a question about scriptless pages and <useBean>:

question: Which are possible outcomes resultingfrom using the following in a JSP document declared as scriptless in the dd.
<jsp:useBean id="mybean" class="net.bean.MyBean" />

He give the correct answer as:
If there is no mybean page-scoped attribute, a new one is created containing a new instanceof net.bean.MyBean.

Ok. However in the explanation of the answer in the back of the book he says:
...D is correct, the only use for <jsp:useBean> in a scriptless environment is to ensure a scoped variable exists.

Now, this may just be a interpretation problem; but, when I read his explanation, I tend to think he is saying that this is a test to ensure the existence of the "id" denoted variable, that is that the variable existed prior to the use of the <useBean> action.
However in the answer D, he indicates that if the variable does not exist it will be created which I know is the behavior of the <useBean> action.

Am I reading too much into his explanation?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

D is correct, the only use for <jsp:useBean> in a scriptless environment is to ensure a scoped variable exists.


I don't think it's true. You can still use getProperty...
 
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe you agree with the answer itself (option D) and the reason for that. So the bit which is unclear for you is this part of the explanation:

the only use for <jsp:useBean> in a scriptless environment is to ensure a scoped variable exists.


What I'm saying here is that the <jsp:useBean> action will ensure the page-scoped variable (since the scope attribute is omitted, so "page" is the default) exists, and if it does not exist it will instantiate a new object of the correct class type and place it in the page-scoped attribute called "mybean".

The net result is therefore that a page-scoped attribute called "mybean" will exist and if it did not exist already, it will be newly created and stored. So this tag does indeed ensure that the scoped variable exists. I'm not staying it tests for existence or provides any other conditional behaviour.
 
Tyler Wright
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Charles,

Human languages allow for all sorts of vague meanings and opportunities for mis-communication.

the only use for <jsp:useBean> in a scriptless environment is to ensure a scoped variable exists.

All I am saying here is that the wording of the answer leaves some questions as to what you are implying.
As I said to begin with,

this may just be a interpretation problem;

regards,
Tyler

 
Charles Lyons
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, I was just under the assumption that you found that part unclear... I didn't take that as offensive, but I did want to clear up any doubt you may have had. And I hope I have clarified that for you?
 
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tyler.
Looks like you are using Charles lyons book.

I am considering buying another book besides HFJS for reference. HFJS is good but somehow it's a little difficult relating different concepts to each other.
I looked into DAvid bridgewater books but didnot find a very good review.Seems it has a lot of errors in it.

I was wondering how you find the Charles Lyon SCWCD.
I am new to JSPs n havent worked on it.So I need to understand the basic before heading to the advanced level!
Is it worth buying??


Thanks.
 
Tyler Wright
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nabila,

You are putting me on the spot...but, that's OK.

I cannot recommend Lyon's book at this time: I am only half-way through it.
Once I have completed it, I will post a review at Amazon and on JavaRanch.

If you have the time, you can use the free study guides found here at JavaRanch to get you started on understanding the basics of Servlets and JSPs.

Also, I have seen a number couple of free and very good tutorials on-line.

One note of caution, besure to confirm that the material you are studying is Servlet 2.4, JSP 2.0, and JSTL 1.1.

regards,
Tyler
 
Nabila Mohammad
Ranch Hand
Posts: 664
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am looking into the javaranch study guides.
If you have any, could you send me the link for a good tutorial.

Thanks for your help and suggesetion!

Take care!
 
reply
    Bookmark Topic Watch Topic
  • New Topic