• 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

jsp:useBean doubt??

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ranchers,

On page 348 of HFSJ, it says that the useBean can also create a bean if it can't find an attribute. So does this mean that it will write the bean class itself if we didn't write one?? If so where will that bean class get stored?? Confusing
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again,



useBean can create a bean OBJECT. It will definetly not create or write a new class.
There is useBean's class attribute witch value specifies a bean's class to be instantiated in case of not finding an attribute.
HFSJ explains it quite clearly I think...
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also on the same page of the book, under the text that says "Turns into this code in the _jspService() method", I'm confused with the line

person = (foo.Person)_jspx_page_context.getAttribute("person", PaegContext.REQUEST_SCOPE)

Now in the jsp:useBean that is shown above this in the book, has the scope set to request...than how comes in the _jspService() method, the above code has _jspx_page_context.getAttribute(...), the one in bold in the above code??

Please clarify me ranchers...
 
Stary Kapec
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Now in the jsp:useBean that is shown above this in the book, has the scope set to request...than how comes in the _jspService() method, the above code has _jspx_page_context.getAttribute(...), the one in bold in the above code??



I do not quite understand.

_jspx_page_context is a reference to PageContext. By PageContext you can read attributes from all scopes using an overloaded getAttribute(String, int) method.

The line you quoted tries to get "person" attribute from the request scope.
useBean tag at first tries to search for an attribute named by "id" in the specified scope. The line you quoted does the job.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jasiek,

I really didn't know that _jspx_page_context is a reference to page context...Where can I get such knowledge, I'm now on chapter7 of the head first book...Since, I didn;t know this, should I have to go back to previous pages and study anything again?? Please help me.
 
Stary Kapec
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have polish edition of the book so I cannot tell you to witch page you should skip exactly.
In the chapter 7 there is an example of the generated servlet class (based on counter jsp). There you can see what the _jspx_page_context is.

But you should not study it! It is Tomcat-specific. You do not have to know exactly how useBean is implemented, and you should NOT really care. All you must know is what useBean does, not how.
 
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I really didn't know that _jspx_page_context is a reference to page context...Where can I get such knowledge, I'm now on chapter7 of the head first book...Since, I didn;t know this, should I have to go back to previous pages and study anything again?? Please help me.



Go through the generated servlet code to get a clear picture....it should clear all your doubts...if you're using Tomcat you should find it at <TOMCAT diretory>/work/Catalina/localhost/<app-name>/org/apache/jsp
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jasiek Motyka.
 
Always! Wait. Never. Shut up. Look at this tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic