• 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

doubt in scriptless JSPs

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I read the following concept from the Head First Servlets and JSP book (second edition)(page 420)
The following is an abstract Bean class person

The following is the subclass of Person



The following is the standard action in a jsp file






The following is the servlet code





Now coming to my problem
The book says The servlet code FAILS at request time,The person attribute is stored at request scope,so the <jsp:useBean>tag won't work since it specifies only a type.The Container KNOWS that if you have only a type specified there must be an existing attribute of that name and scope


My doubt is

1.How the servlet code is linked to the jsp page I mean there is no form action tag given here?[/B

2.[B]What is request time ?


3.How is the person attribute's scope related to the type of the useBean tag


Please do help me Thank you in advance.....
 
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
Please avid the overuse of bold.

Originally posted by nidhivel raja:
1.How the servlet code is linked to the jsp page I mean there is no form action tag given here?

The servlet code is not linked to the JSP. That's the beauty of loose coupling. The servlet has created a scoped variable named person (via setAttribute()) that is available to the JSP.

2.What is request time ?

When the request is being executed.

3.How is the person attribute's scope related to the type of the useBean tag

The useBean tag will look for the scoped variable in a specified scope or all scopes.
 
nidhivel raja
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Mr.Bear Bibeault ,for your timely help.So the useBean can only use the variable if it is in the request scope right?

My question is how this problem can be solved i mean when exactly a request scope is created .......Is it created when a servlet services another jsp's request or when the servlet is compiled?


 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is fairly obvious if you invoke the jsp directly, you will get a runtime error, because the bean "person" is not in scope, and it can't create one on the fly.

The servlet's responsibility is to set up the "person" bean, so that the jsp can use it.

What links the two? What tells it to run the servlet first and then the JSP? And which JSP?
That is normally the job of a "controller"

Normally code something like this:


If this was in your servlet it would tell it to forward to the jsp "fooTest.jsp" once it was finished processing.


The HttpRequest is triggered by exactly that. A client (normally a browser) making a request of the server. The server receives the connection from the browser, creates an HttpServletRequest object for you to use, and then invokes the servlet/jsp which was referenced, passing in the request object as a parameter. This is all done by the servlet container.

Request scope is the scope of one request-response cycle. Ie the server receives a request from the browser, and sends back a response.
Session scope (by contrast) can go over multiple requests from the same user.
You can specify any of the 4 attribute scopes for a bean to "live" in and it will look for it there.

Cheers,
evnafets
 
nidhivel raja
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Mr.Stefan Evans I have solved that problem........
reply
    Bookmark Topic Watch Topic
  • New Topic