aspose file tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes [SCWCD] Difference between ${request} and ${requestScope} Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of RabbitMQ in Depth this week in the Open Source forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "[SCWCD] Difference between ${request} and ${requestScope}" Watch "[SCWCD] Difference between ${request} and ${requestScope}" New topic

[SCWCD] Difference between ${request} and ${requestScope}

Paulo Gervásio.

Joined: Aug 14, 2010
Posts: 12

I have a doubt with these parameters included in EL.

I thought that ${requestScope} contained a map with the request attributes and the ${request} object was exactly a HttpServletRequest "javaBean".
But using the ${request} object, I couldn't get the others objects in this object like getServerPort(), getContextPath() etc... (I just can do it using ${pageContext.request.serverPort}, for example).

And now I have this doubt... What's the difference between ${request} and ${requestScope}? Are they equals?

Paulo Gervásio

Mark Uppeteer
Ranch Hand

Joined: Mar 02, 2004
Posts: 159

Hi Paulo,

there is no request object in EL. On requestScope your view is right.

in EL you have to use pageContext to get to your request object.
PageContext is the only non map like object.
So ${pageContext.request} is what you need.


I know where my towel is. (SCJP 5, OCPJWCD)
[Free Quiz Tips for a fun night with friends or family] Flash games
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper

Joined: Apr 07, 2010
Posts: 1986

Hi Paulo,

What's the difference between ${request} and ${requestScope}? Are they equals?

In EL you have different implicit objects then for a JSP.

Have a look at my notes (SCWCD notes) and read chapter 7.11.10 and compare it with chapter 6.3.


[EDIT: Mark, you beat me there....]
Paulo Gervásio.

Joined: Aug 14, 2010
Posts: 12
Excuse me, but I can't understand the difference between the parameters....

I wanna know which method there are in one that there aren't in other....

Paulo Gervásio.

Joined: Aug 14, 2010
Posts: 12
I find the answer here

Thanks for help!

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 62746

Here it is in plainer language: ${request} does not exist!

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Alx Tabanas

Joined: Jan 20, 2011
Posts: 2


In Servlet:
request.setAttribute("person", new Person("John Ba"));

Now what is exactly the differnece between:

${} and ${}

FYI: output is the same

Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Hi Alx,

${} prints the same because the ${attributeName} looks for attributeName in all scopes. It starts with page scope, then request, then session and then application.
In your case, it can't find "person" in page scope, so it then looks for the request sope. It founds it there and prints it, so the result is the same.

Try setting "person" attribute i.e. in both - request and application scope in servlet. The ${} will print just the request scope one.


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Vijitha Kumara

Joined: Mar 24, 2008
Posts: 3882

And Welcome to CodeRanch, Alx Tabanas

[How to ask questions] [Twitter]
Alx Tabanas

Joined: Jan 20, 2011
Posts: 2

big thanks

I agree. Here's the link:
subject: [SCWCD] Difference between ${request} and ${requestScope}