2

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.

jsight
  • 27,819
  • 25
  • 107
  • 140
  • What library & language? What do you mean by set Attribute? Also, please don't use "?!?!?!?!?!?" in your title, it doesn't help anyone. – Ian P Jul 26 '09 at 17:59
  • I assume it's Java since he has a servlet – Brian Agnew Jul 26 '09 at 18:12
  • @Brian - I think so, since those class names align with Java, and specifically the Apache HTTP-Client library. – jsight Jul 26 '09 at 18:20
  • Thanks. I forget that forms in HTML cant only accept text. Cant accept objects. Attributes is set on the server side so servlets can use it. Got it. thanks. –  Jul 26 '09 at 18:55

2 Answers2

5

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
  • 27,819
  • 25
  • 107
  • 140
0

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
  • 268,207
  • 37
  • 334
  • 440