[Logo]
Forums Register Login
EL param and page scope vars
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???
(1 like)
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.
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.
 
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.
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']
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
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.
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 ]
Thanks a lot......
it helped a lot.....
 
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!
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Dec 15, 2017 20:40:45.