Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet & jsp related doubt

 
vianyrajnish rajnish
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64973
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 ]
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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 Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
hi Jothi Shankar Kumar,

Thank you....


thanks ,

Vinay rajnish
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic