HttpClient请求设置属性问题

发布于 2024-07-29 02:40:01 字数 579 浏览 2 评论 0原文

我使用这个 HttpClient 库玩了一段时间(几周)。 我想以某种方式将属性设置为请求。 不是参数而是属性。 在我的 servlet 中,我想使用 Integer inte = (Integer)request.getAttribute("obj");

我不知道我想念什么。 我试试这个。

NameValuePair[] pair = new NameValuePair[1];
pair[0] = new NameValuePair();
pair[0].setName("aloha");
pair[0].setValue("value");

但这个设置参数不是属性.. 我也使用它,因为这只是一个具有接受字符串和对象的方法的对象。 还是没有解决。

HttpClientParams clParam = new HttpClientParams();
clParam.setParameter("obj", new Integer(24405));
method.setParams(clParam);

请给我一些线索...... 谢谢。

I play for a while (couple of weeks) with this HttpClient lib.
I want somehow to set Attribute to the request. Not parameter but Attribute. In my servlet I want to use Integer inte = (Integer)request.getAttribute("obj");

I have no idea what i miss. i try this.

NameValuePair[] pair = new NameValuePair[1];
pair[0] = new NameValuePair();
pair[0].setName("aloha");
pair[0].setValue("value");

but this set parameters not attributes..
I also use this because this is only one object who have method that accept string and object. Still not resolved.

HttpClientParams clParam = new HttpClientParams();
clParam.setParameter("obj", new Integer(24405));
method.setParams(clParam);

Please give me some clue....
Thx.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

脸赞 2024-08-05 02:40:01

我相信您误解了 setAttribute/getAttribute 方法。 放入“getAttribute”检索请求中的数据只能通过服务器上的 setAttribute 调用进行设置。 客户端无法强制在那里设置值,因为将参数从客户端传递到服务器的唯一方法是通过参数(或 POST 请求中的某种其他结构)。

getAttribute/setAttribute 实际上用于在使用 请求调度程序

I believe that you have misunderstood the purpose of the setAttribute/getAttribute methods. The data placed into the request for retrieval by "getAttribute" can only be set with the setAttribute call on the server. The client cannot force values to be set there, as the only way to pass parameters from the client to the server is via parameters (or some sort of other structure inside of a POST request).

getAttribute/setAttribute are really used for passing information between pieces of server code when using RequestDispatcher.

白龙吟 2024-08-05 02:40:01

来自 servlet请求 API

属性可以通过两种方式设置。 这
servlet容器可以设置属性
提供可用的自定义信息
关于一个请求。 例如,对于
使用 HTTPS 发出的请求,
属性
javax.servlet.request.X509Certificate
可用于检索有关的信息
客户的证书。
属性也可以设置
以编程方式使用
setAttribute(java.lang.String,
java.lang.Object)。 这允许
要嵌入到的信息
在 RequestDispatcher 之前请求
打电话。

您实际上是指属性吗? 您是否想从客户端设置参数HTTP标头

From the servlet request API

Attributes can be set two ways. The
servlet container may set attributes
to make available custom information
about a request. For example, for
requests made using HTTPS, the
attribute
javax.servlet.request.X509Certificate
can be used to retrieve information on
the certificate of the client.
Attributes can also be set
programatically using
setAttribute(java.lang.String,
java.lang.Object). This allows
information to be embedded into a
request before a RequestDispatcher
call.

Do you actually mean attribute ? Do you perhaps want to set a parameter or an HTTP header from the client ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文