views:

854

answers:

2

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

Please give me some clue.... Thx.

+2  A: 

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.

jsight
A: 

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 ?

Brian Agnew