wood burning stoves 2.0*
The moose likes JSP and the fly likes does this jsp code will work? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Reply locked New topic

does this jsp code will work?

vianyrajnish rajnish
Ranch Hand

Joined: Apr 22, 2007
Posts: 70
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" />

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();

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();

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 ..

Vinay Rajnish
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Duplicate of:

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.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
It is sorta covered in the JavaRanch Style Guide.
subject: does this jsp code will work?
Similar Threads
HFSJ doubt :Pg:356
bean-related standard actions exercise
Is this an error in HFSJ ??
servlet & jsp related doubt
useBean doubt