• Post Reply Bookmark Topic Watch Topic
  • New Topic

Request Scope in jsp  RSS feed

 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
consider i am having 3 jsp pages A , B , C.
scope= page - > java bean available for particular jsp
request - > Request goest from A to B , will java bean available for both A , B or B only
session - > java bean available until the session goes invalid
application - > java bean object available entire application(until server shutdown or closing application)

My question , In request scope java bean object available for Both A,B or B only.
 
Prashant Hurria
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple rule of thumb till the request is travelling inside the server whatever is in the request scope stays .....
That means if you send a request from one servlet to other (or One jsp to the other ) using request dispatcher the objects put in the request are available .
But as soon as a response is sent the earlier request object dies..
So if on your side it is a Server side redirection using request dispatcher the bean will be available to both the pages but if it is a client side redirect the bean will be lost .....
 
Nilesh Miskin
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prashant Hurria wrote:
But as soon as a response is sent the earlier request object dies..

A developer can maintain reference to the request object outside the scope of the service method. However this is not recommended as the result might be unpredictable.
That's because containers commonly recycle request objects in order to avoid performance overhead.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nilesh Miskin wrote:A developer can maintain reference to the request object outside the scope of the service method.

This should never, ever be done! Ever.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!