• 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

servlet & jsp related doubt

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

This is taken from Kathy Sierra..Head first jsp and servlets

jsp code is like this below:

<jsp:useBean id="person" type="foo.Employee">
<jsp:setproperty name="person" property="name" value="Fred" />
</jsp:useBean>

Name is <jsp:getProperty name="person" property="name" />


questions are :
what happens if the sevlet code is like this

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

answer :
fails at request time . The person attribute is stored at request scope
so <jsp:useBean > tag wont work because it can't find bean attribute .

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

answer : this works fine and prints out "Evan"

-------------------------------------------------

my doubt is in both 1) and 2) question the person attribute is having request scope only ...then how the 2) will run succesfully.
( in jsp above ther is no scope , so default is page scope )


can anyboby please answer this ..

thanks,

Viany Rajnish
[ July 11, 2007: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you missing something?
1) and 2) look the same to me.

Did you mean to post a second version of the JSP code?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please do not post the same question in multiple forums.
This is called cross-posting.
It causes confusion and duplication of effort which will annoy the people who would otherwise help you making it less likely that you will get an answer to your question.

I closed the topic in the JSP forum.

If you're not getting an answer to your question, maybe you could improve the question. We have some tips for doing so here
 
vianyrajnish rajnish
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

questions 1) and 2) are not same

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



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

--------------------------

here Employee class is inheriting Person class.

See the assignments objects of references

Thanks,
Vinay Rajnish
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only difference is how p can be used in the servlet after its declarations. In one, p can only be treated as a Person. In two, it can be treated as an Employee.

What happens later, like in a JSP, depends on what you do later.
[ July 13, 2007: Message edited by: Bear Bibeault ]
 
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
Did you try to check the errata for this? Check it at http://www.oreilly.com/catalog/headservletsjsp/errata/headservletsjsp.confirmed
 
vianyrajnish rajnish
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jothi Shankar Kumar,


Thanks for the reply ... I found the error following the errata ..

but who writes these errata for the book...

( this is not to be posted here but i am curious to know)

thanks all

Vinay rajnish
 
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
I guess if you visit the SCWCD forum, there is a link which leads you to the errata website. Also note that, any software book will for sure have a site dedicated to errata's. You can be doubly sure of that.
 
vianyrajnish rajnish
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Jothi Shankar Kumar,

Thank you....


thanks ,

Vinay rajnish
 
reply
    Bookmark Topic Watch Topic
  • New Topic