• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Page Scope and Request Scope

 
Manohar Karamballi
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai All!
What are advatages of having page scope beans instead of request scoped variables? Also pls advise me if there are any pitfalls in using page scope as i am facing some problems in using page scrope..

TIA
Rgds
Manohar
 
Junilu Lacar
Bartender
Posts: 7480
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I guess one advantage would be that your request objects will have fewer attributes to carry around.
What exactly are the problems you are facing?
The only pitfall I can think of right now is not having a clear idea of the difference between the lifetime/scope of a bean that has page scope vs. request scope.
Remember, JSPs are translated into servlets. Beans that have page scope are local objects created in the generated service() method. Page-scoped beans go away when execution of the service() method termininates.
OTH, beans that have request scope are kept in the request object which is passed to the service() method. They are available in the service() method through request.getAttribute("bean name"). They remain available as long as the request object is available. That means if you are doing forwards, the same request-scoped bean will be available to the JSP/servlet you forward to.
HTH
------------------
Junilu Lacar
Sun Certified Programmer for the Java� 2 Platform
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic