differences between Request Attributes and Request Parameters

本文讨论了HTTP请求中的参数与属性的区别。参数是从HTML表单传递的字段值对,其值为字符串类型;而属性是在Java Server环境中传递的对象名值对,其值可以是任意Java对象。文章还探讨了如何在Servlet中使用这些参数创建对象并将其作为属性存储。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值