HttpClient的要求设置属性问题 [英] HttpClient request set Attribute question

查看:154
本文介绍了HttpClient的要求设置属性问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我玩了一段时间(2周左右)这个HttpClient的库。
我想以某种方式属性设置为请求。没有参数​​,但属性。在我的servlet我想用整数INTE =(整数)request.getAttribute(目标文件);

Hi 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);

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

Please give me some clue.... Thx.

推荐答案

我相信,你误会的<一个目的href=\"http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/ServletRequest.html#setAttribute%28java.lang.String,%20java.lang.Object%29\"相对=nofollow>的setAttribute / 的getAttribute方法。由的getAttribute放置到用于获取请求的数据只能用在服务器上的setAttribute呼叫设置。客户端不能强迫值被设置在那里,以从客户端传递参数到服务器的唯一方法是通过参数(或某种其它结构的POST请求的内侧)。

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真正用于使用的 RequestDispatcher的

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

这篇关于HttpClient的要求设置属性问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆