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
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
Author

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

Paulo Gervásio.
Greenhorn

Joined: Aug 14, 2010
Posts: 12
Hello!

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?

Thanks.
Paulo Gervásio

SCJP
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.


br,
mark


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
Bartender

Joined: Apr 07, 2010
Posts: 1675
    
  25

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.

Regards,
Frits

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

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....


Thnks
Paulo Gervásio.
Greenhorn

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

Thanks for help!

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

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


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

Joined: Jan 20, 2011
Posts: 2

hello

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

Now what is exactly the differnece between:

${requestScope.person.name} and ${person.name}

FYI: output is the same


Thanks
Alx
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Hi Alx,

${person.name} 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 ${person.name} will print just the request scope one.

Cheers!


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
Bartender

Joined: Mar 24, 2008
Posts: 3829

And Welcome to CodeRanch, Alx Tabanas

SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Alx Tabanas
Greenhorn

Joined: Jan 20, 2011
Posts: 2

big thanks


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [SCWCD] Difference between ${request} and ${requestScope}