• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

jsp:usebean confusion

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all !!!

Q.from Free scwcd mock exam for jsp by Nikos

Consider this code.

What is the output when the form is submitted? (1 correct answer)

1. I like null!
2. I like Head First Servlets and JSP!
answer 1

why not the answer 2.?
cant property set by input.jsp not retrieve in output.jsp ...as scope given is request......i think the request remains the same in both jsp..
please help....thanks in advance
 
Sheriff
Posts: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i think the request remains the same in both jsp.



And what makes you think so?? When you press the click here link on input.jsp, a new request is sent to the server to access output.jsp. So the Book bean set in the request to input.jsp, is not available. Remember, each time you request something from the server, a new request is sent...
 
Ranch Hand
Posts: 257
Hibernate Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The trick here is in <jsp:usebean > tag which creates the object as an attribute in the mentioned scope. In this case <jsp:setProperty > is the counter part of request.setAttribute (if the scope is selected as request).

As you might be aware that all the request attributes set in a jsp remain in the same jsp and are lost as soon as the request object available in that jsp is lost. You can refer the following section in useBean syntax

request - You can use the Bean from any JSP page processing the same request, until a JSP page sends a response to the client or forwards the request to another file. You can use the request object to access the Bean, for example, request.getAttribute(beanInstanceName).



If you want the attribute to be available in another jsp as well you shall have to save the object in session. like in following secion





Regards
Salil Verma
 
geet rahane
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ankit and Salil!!!
 
Your mother was a hamster and your father was a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic