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

does this jsp code will work?

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • 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,
Vinay Rajnish
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Report post to moderator
Duplicate of:
https://coderanch.com/t/364633/Servlets/java/servlet-jsp-related

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic