hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davidecr <david...@gmail.com>
Subject Re: Help on Requst Params in Post
Date Sun, 09 Apr 2006 18:25:18 GMT
Hi i'mactually doing this in a project and to send objects and keep the 
parameters appart I send the parameters appenden to the end of the 
url... something like:

new PostMethod("theURLofMyServlet" + "?" + "myparameter1" + "=" + 
"myparameter1VALUE");

and use a RequestEntity to send the objects...


... in the servlet I use something like

int param1 = Integer.parseInt(request.getParameter("myparameter1"));
 to get the parameter and ... to get the objects something like

 in = new ObjectInputStream(new 
BufferedInputStream(request.getInputStream()));

        //get the client id
        int clientId = (Integer) in.readObject();


this is a silly example sorry i dont send you a better example because y 
made a group of classes that help me to handle this type of processing 
so i decide to write this instead of sending the real code...

maybe someone else can see this nad make and opinion if there is a 
better way

--
David Casta;eda

Sheetal D wrote:
> Hi Roland,
>          Thanks for showing me the right way, 
>   Could you clarify me one more doubt,
>   If I want to write params and as well objects,  
>   Should i use ByteArrayPart with StringPart, is this the right way.  or Is there any
other better ways of doing this.
>    
>   Thanks,
>   Sheetal
>    
>   
> Roland Weber <http-async@dubioso.net> wrote:
>   Hello Sheetal,
>
>   
>> post.addRequestParameter("1","2");
>> post.addRequestParameter("3","4");
>> post.setRequsetEntity();
>> // These two will not work together,
>>     
>
> Right, they won't. Either you set the parameters which will create
> a request entity with url-form-encoding, or you set a request entity
> and the parameters will be ignored.
> If you set a request entity and still need to set parameters, you
> probably need the multipart request entity which will not be parsed
> by the servlet engine, as you have detected. If you need to do a
> file upload, you will have to use the multipart request entity.
>
>
>   
>> When I use parts, Again I need to use ObjectInopuStream and read accorndly,
>>     
>
> You *never* use an ObjectInputStream, unless you have to deserialize
> Java objects!
>
>   
>> Is it should always read using OutputStream.
>>     
>
> You cannot read from an OutputStream. Output streams are for writing.
>
> You can use the InputStream of the request object on the server side
> to access the multipart-encoded request entity. Since you will need
> a server-side parser for multipart request entities, you should have
> a look at the FileUpload project:
>
> http://jakarta.apache.org/commons/fileupload/
>
>
> hope that helps,
> Roland
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-help@jakarta.apache.org
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Mime
View raw message