java - Dynamic form, with or without multipart/form-data -
i designing simple crud framework in java, in html page have dynamic form (2 multipart create , update file upload , 1 without fileupload , multipart delete). server side, request modulator checks parameters using request.getparametermap();
, checks hidden type input <input type="hidden" name="returntype" value="create">
whether create, update or delete operation. based on call necessary handlers.
note: form enctype , encoding set multipart/form-data note: parammap.size() returns 0 here , returntype getting null , getting null pointer exception.
if not use enctype , encoding @ runs fine, again file upload gives me exception encoding type shoud multipart/form-data. can me in way can have dynamic form can create crud? or why not able use request.getparametermap();
multipart/form-data :)
given below code of request modulator
public string identifynow()throws servletexception, java.io.ioexception { uploadxmlagent uploadagent; parammap=request.getparametermap(); if (parammap == null) throw new servletexception( "getparametermap returned null in: " + getclass().getname()); iterator=parammap.entryset().iterator(); system.out.println(parammap.size()); while(iterator.hasnext()) { map.entry me=(map.entry)iterator.next(); if(me.getkey().equals("returntype")) { string[] arr=(string[])me.getvalue(); returntype=arr[0]; } } //identified based on returntype, instantiate appropriate handler if(returntype.equals("create")) { uploadagent=new uploadxmlagent(realpath,request,parammap); uploadagent.retrievexml(); //some more operations return uploadagent.uploadxml(); } else if(returntype.equals("update")) { system.out.println("update"); uploadagent=new uploadxmlagent(realpath,request,parammap); uploadagent.retrievexml(); //some more operations return uploadagent.uploadxml(); } else if(returntype.equals("delete")) { //some operations } return returntype; }
as per comment on other answer:
can use
request.getparametermap();
in way multipart?
if sole requirement, create filter
parsing work , prepares request parameter map parsed multipart items can continue using getparameter()
, getparametermap()
, consorts usual way in jsp/servlet. can find complete example of such filter here.
Comments
Post a Comment