• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EL param and page scope vars

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if a variable is set in the page scope, in EL we access it as ${varName}. I have a request parameter. Is it a neccesity to explicity specify the scope and get the value by ${param.varName}.

If no scope is specified does it not find the parameter in all the scopes.

i tried accessing the var by ${varName} and value is not found but ${param.varName} gives the value. Why???
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Beacuse param is not a scope. it is a Map of all the request parameters. The scopes, and their order of implicit search are: page, request, session and application.
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as you said 'param' is a map of request parameters, will the request scope not contain this param.It will right?? I mean the request parameters will be in the 'param' map as well as the 'request' object.

so in that case, even if i refer to the var as ${varName}, and this varName is not in the page scope.... will it not fall back to the request scope and find this parameter there....

If i m not correct, please explain this or refer to some links.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I mean the request parameters will be in the 'param' map as well as the 'request' object.



No, they will not.

To be completely correct, neither parameters nor scoped variables are "in" the request object. The request makes the parameters available, and maintains a map of scoped variables.

so in that case, even if i refer to the var as ${varName}, and this varName is not in the page scope.... will it not fall back to the request scope and find this parameter there....



If varName is a scoped variable, the expression ${varName} will search page, request, session and application scopes respectiely.

If varName is a parameter, it exists in none of these scopes and can only be accessd via the param or paramValues maps;

If i m not correct, please explain this



Request parameters and scoped variables are separate and distinct concepts. Don't confuse them.
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
u know wat.. i never thot posting queries will help me clear the rest issues as well... but i really find it cool... its adding lotsa value..
Thanks Bear... thanks a lot...

but the queries are still increasing .. please help

u said

'Request parameters and scoped variables are separate'

i am not very clear by what u mean by this..
do you mean.....

that scoped varibles are those.. which you set using
<c:set var="varName" scope="request" />
or using request.setAttribute("varName","varNameValue");

and parameters are...
request.getParameter();

Also,what with the request attributes....
how do i access those.... will i be able to access those using ${param.dog}
and the values in it by ${param.dog.name}
[this is said to find out if attributes(objects) are accessible by 'param']
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Request parameters come from the browser (the HTML).
They can be sent to the server as querystring parameters:


or as form parameters:


You would retrieve these in your servelet with: request.getParameter("first_name")

In a JSP, with EL you retrieve it with the param keyword:
${param.first_name}

They can not be objects because browsers can't send objects.
They are always Strings or arrays of Strings.


Scoped variables, on the other hand are objects which are bound to page, request, session, or application scope.

These variables can be accessed directly from EL
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What Ben said.

Additionally, I would add to

Scoped variables, on the other hand are objects which are bound to page, request, session, or application scope.



These objects are bound into the scopes using the setAttribute methods of those scopes, the <c:set> tag, or even the <jsp:useBean> tag which will create and bind a variable into a scope if it does not already exist.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe this will clear things up.
On the left: an EL expression.
On the right: the Java equivalent.


The main points to note:
- request parameters are NOT request attributes. They are two completely different concepts.
- the difference between getAttribute and findAttribute methods. The first looks in only one scope. The second looks in all of them going through page, request, session, application attributes in that order.
[ November 24, 2005: Message edited by: Stefan Evans ]
 
geeta lalchandani
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot......
it helped a lot.....
 
Ranch Hand
Posts: 89
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ben Souther wrote:
or as form parameters:





i would like to quote on this,.. should it be input type="text" name="first_name"...
btw, i learned from your explanation... thanks!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic