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

request vs. pageContext

Egil Poma
Ranch Hand

Joined: Nov 23, 2002
Posts: 40
What's the difference on putting a variable in request (request.setAttribute) vs. putting it in pageContext (pageContext.setAttribute)?

Variables in both scopes seems to live only for a single page view. So is there a difference?
ramesh kumar

Joined: Aug 15, 2006
Posts: 25
if we add variables to PageContext we can use them directly,if add them to request object we need to use getAttribute() method to get value
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

Originally posted by ramesh kumar:
if we add variables to PageContext we can use them directly

I have no idea what is meant by this. Scoped variables in page scope are accessed in the same manner as in any other scope.

The difference is in the scope of the variables (where they can be accessed from) and in their life span.

Page-scoped variables are only available in the current page; not included pages, not forwarded pages. Request-scoped variables are available to every resource that participates in the creation of the response. They are most often used to pass data from a servlet controller to its view JSP.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: request vs. pageContext
It's not a secret anymore!