File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Page Scope and Request Scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Page Scope and Request Scope" Watch "Page Scope and Request Scope" New topic

Page Scope and Request Scope

Manohar Karamballi
Ranch Hand

Joined: Jul 17, 2001
Posts: 227
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..

Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

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.
Junilu Lacar
Sun Certified Programmer for the Java� 2 Platform

Junilu - [How to Ask Questions] [How to Answer Questions]
I agree. Here's the link:
subject: Page Scope and Request Scope
It's not a secret anymore!