set variables on request

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

set variables on request

Bubulina
Hello,

I know that i can get value from a request like this:
"#set($name= $request.getParameter('name'))"

Now, shouldn't i be able to put variables on request so i can use in the html page? something like this:
"#set($var = $request.setAttribute($name))"

and in the html page to use $request.getAttribute($name) ?

Thank you
Reply | Threaded
Open this post in threaded view
|

Re: set variables on request

lucaa
Hi Bubulina,

On 12/16/2009 11:40 AM, Bubulina wrote:
>
> Hello,
>
> I know that i can get value from a request like this:
> "#set($name= $request.getParameter('name'))"
>
> Now, shouldn't i be able to put variables on request so i can use in the
> html page? something like this:
> "#set($var = $request.setAttribute($name))"

yes, normally yes, but you also have to pass a value, the setAttribute()
function gets 2 params:

$request.setAttribute($name, $value)

>
> and in the html page to use $request.getAttribute($name) ?

I confess I don't really understand which HTML page this is about, but yes, it
should work. However, keep in mind that parameters and attributes are not really
the same thing (see the spec here
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletRequest.html ).

Happy hacking,
Anca

> :blush:
> Thank you
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: set variables on request

Marius Dumitru Florea
In reply to this post by Bubulina
Bubulina wrote:

> Hello,
>
> I know that i can get value from a request like this:
> "#set($name= $request.getParameter('name'))"
>
> Now, shouldn't i be able to put variables on request so i can use in the
> html page? something like this:
> "#set($var = $request.setAttribute($name))"
>
> and in the html page to use $request.getAttribute($name) ?

Have you read
http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#setAttribute%28java.lang.String,%20java.lang.Object%29

It clearly states "Attributes are reset between requests". Also, please
note that attributes and parameters have a different meaning when you
talk about servlet requests.

Isn't an input hidden (HTML element) what you are looking for? Or maybe
http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpSession.html#setAttribute%28java.lang.String,%20java.lang.Object%29

Hope this helps,
Marius

> :blush:
> Thank you
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: set variables on request

Bubulina
In reply to this post by lucaa
just setting the var on request and reading it afterwards. it worked.
thank you

lucaa wrote
Hi Bubulina,

On 12/16/2009 11:40 AM, Bubulina wrote:
>
> Hello,
>
> I know that i can get value from a request like this:
> "#set($name= $request.getParameter('name'))"
>
> Now, shouldn't i be able to put variables on request so i can use in the
> html page? something like this:
> "#set($var = $request.setAttribute($name))"

yes, normally yes, but you also have to pass a value, the setAttribute()
function gets 2 params:

$request.setAttribute($name, $value)

>
> and in the html page to use $request.getAttribute($name) ?

I confess I don't really understand which HTML page this is about, but yes, it
should work. However, keep in mind that parameters and attributes are not really
the same thing (see the spec here
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletRequest.html ).

Happy hacking,
Anca

> :blush:
> Thank you
_______________________________________________
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users