Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

HFSJ: Be the Container: page 358

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

This book rocks...I mean, its like crack. I can't get enough... but I have a question which I don't really understand from the book. I'm tempted to believe its wrong...but I could be too because they're certified and I'm still posting.

The question is on page 358:
You have JSP Code:

It basically says what happens if the servlet code looks like this:



now, according to the book, it blows up...but here's the thing, wouldn't the variable be on the existing page since the jsp being specified is requesting a scope of request type and this is exactly the same scope that is being set in the attribute of the calling servlet BEFORE it forwards to the jsp?

Am I too interprete page 356 which states Result if the person attribute already exists in "page" scope strictly? Or is it...wrong?
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael ... as per the code you have given..



when you give the type alone,it means.. the container just looks for the available bean object and its clear ofcourse.. the point here is if we do not specify the class type and by chance if the bean does not exist in the scope .. the container has no way to know which object reference we need to assign since there is no class..


the above code you have provided is not corret in this context.. and which hfsj book are you using.. hfsj 2nd edition .. ?? page 358 has different information.. dude... i know i have answered only partially ..
 
Michael Vargenstien
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. Yeah, this is the 2nd edition (Updated for EE5) version. The best way to prove this is probably just do it on my own (write an application) and post the results.

Do you think they will let met use the compiler for the test?
 
Sarat Koduri
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
he he he... .. ya even i do not i understand why don't they allow us to use the compiler in the exam. ofcourse if we know the code only we can write.. and the objective of the exam is to prove that we know the coding..

Sun should consider this..option of allowing people to use compiler during the exam. ..
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FWIW this is mentioned a couple of times in the "unconfirmed" errata pg420 for the 2nd edition:

http://oreilly.com/catalog/9780596516680/errata/

I agree with the comments, it should work, and when I tried it, it appeared to work!

Worth checking the rest of the errata, in particular the mock section IMHO!

Rufus.
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

can anyone give a confirm answer regarding this , no final conclusion since few years ?

my understanding is that

====

from the servlet code , it is a polymorphic reference

foo.Person p = new foo.Employee();
p.setName("Evan");
request.setAttribute("person", p);

so for the standard action , it will only work with this
<jsp:useBean id="person" type="foo.Person" class="foo.Employee" scope="request" />

====

if you want this to work
<jsp:useBean id="person" type="foo.Employee" scope="request" />

for the servlet code, you need to have the same reference type and object type
foo.Employee e = new foo.Employee();
p.setName("Evan");
request.setAttribute("person", e);

====

can anyone clarify this ?
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

from the servlet code , it is a polymorphic reference

foo.Person p = new foo.Employee();
p.setName("Evan");
request.setAttribute("person", p);

so for the standard action , it will only work with this
<jsp:useBean id="person" type="foo.Person" class="foo.Employee" scope="request" />



The above will also work with following:

<jsp:useBean id="person" type="foo.Person" scope="request" />

AND

<jsp:useBean id="person" type="foo.Employee" scope="request" />

if only the "type" attribute is mentioned then the attribute with the same id which in our case is "person" should exist in the "request" scope.

It seems the web container does a check of something like:

if ( person attribute exists in request scope
&& [object referred by attribute "person" stored in "request" scope] instanceof
[type= say "foo.Employee"]
)
THEN
return the reference to that object referred to by person attribute
ELSE
throw an exception
 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic