Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

 
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
 
Ranch Hand
Posts: 159
Eclipse IDE C++ 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
 
Creator of Enthuware JWS+ V6
Posts: 3348
303
Android Eclipse IDE Chrome
  • 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!

 
Marshal
Posts: 67415
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here it is in plainer language: ${request} does not exist!
 
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
 
Ranch Hand
Posts: 623
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!
 
Bartender
Posts: 4107
72
Hibernate Fedora Chrome
  • 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


    Bookmark Topic Watch Topic
  • New Topic