HttpClient请求设置属性问题
我使用这个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信您误解了 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.
来自 servlet请求 API
您实际上是指属性吗? 您是否想从客户端设置参数或HTTP标头?
From the servlet request API
Do you actually mean attribute ? Do you perhaps want to set a parameter or an HTTP header from the client ?