differences between Request Attributes and Request Parameters

来源:互联网 发布:淘宝里,宝贝详情在哪 编辑:程序博客网 时间:2024/06/05 01:06
 
xmike1
12-04-2004, 10:06 PM
Can someone give me a quick description of the differences between a request attribute and a request parameter? I have tried to cycle through all the parameters in a request, using getParameterNames and getParameter,in the hopes that I could modify the data and set it back to the request with setAttribute. This doesn't seem to work.

ray326
12-04-2004, 11:24 PM
A "parameter" is a form field name/value pair passed from the HTML side of the world. Its value is a String.

An "attribute" is a Java object name/value pair passed only through the internal JavaServer processes. (I.e. it can come from a JSP or servlet but not an HTML page.) Its value is an Object.

You can't alter the request parameters, just read them. If you could there would be a setParameter() method. Parameters and attributes do not share a name space so a parameter named "foo" and an attribute keyed "foo" are distinct.

xmike1
12-05-2004, 08:53 AM
Thanks. That was very clear. So I am hosed taking this approach. I guess I would have to interogate these fields at the screen level on a submit. I could use JavaScript to go through each and change them before sending them on. More work but is sounds doable.

If there is a better approach please let me know (anyone).

ray326
12-05-2004, 03:13 PM
If you know your users have Javascript enabled then you could certainly massage the parameters before submitting the form. A better way might be to let the servlet create an object using the parameter values then using that object as an attribute.
from:http://www.webdeveloper.com/forum/archive/index.php/t-50637.html