Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Paulo Gervásio.
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mark Uppeteer
Ranch Hand
Posts: 159
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2534
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I find the answer here

Thanks for help!

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here it is in plainer language: ${request} does not exist!
 
Alx Tabanas
Greenhorn
Posts: 2
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Welcome to CodeRanch, Alx Tabanas
 
Alx Tabanas
Greenhorn
Posts: 2
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
big thanks


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic