java - How to post multiple types of parameter together in Apache HttpPost -
i facing weird issue code. using org.apache.http.entity.mime.multipartentity
class submit file entity server can upload file. when trying add entity/parameter, value not been able capture through httpservletrequest
. below client side working code sending successful file upload request:
public class testclass { public static void main(string args[]) throws configurationexception, parseexception, clientprotocolexception, ioexception { httpclient client = new defaulthttpclient(); client.getparams().setparameter(coreprotocolpnames.protocol_version, httpversion.http_1_1); httppost post = new httppost("http://localhost:9090/hostimages/imageuploaderservlet"); multipartentity entity = new multipartentity( httpmultipartmode.browser_compatible ); entity.addpart( "file", new filebody(new file("d:/tempimage/cat_image.jpg") )); post.setentity(entity); string response = entityutils.tostring( client.execute( post ).getentity(), "utf-8" ); client.getconnectionmanager().shutdown(); } }
on server side, i.e. inside imageuploaderservlet
parsing request
object of httpservletrequest
follows:
fileitemfactory fileitemfactory = new diskfileitemfactory();
, gives me list of file submitted through client side absolutely work fine.
servletfileupload servletfileupload = new servletfileupload(fileitemfactory); list fileitems = servletfileupload.parserequest(request);
problem arises when trying add entity either using multipartentity
or httpparams
unable value @ server end. have gone through this question posted no help. (i tried add entity stringbody
below:)
entity.addpart("flag", new stringbody("true"));
i want add additional parameters @ client side can use @ server side serve purpose. additional parameter either string, int or byte whatsoever. dont know exact problem lies, client side or server side ! kindly help.
multipart requests need special attention. here useful link thread can understand how treat these cases:
convenient way parse incoming multipart/form-data parameters in servlet
regards
Comments
Post a Comment