upload multiple files with html5 multiple attribute - spring mvc -
i trying upload multiple files using html5 attribute multiple. link provide me start. however, facing problem not able read multipartfile in controller.
here pojo class
public class fileproduct { private string name; private list<multipartfile> images; }
my controller
public string processnewlisting(model model , @modelattribute fileproduct product , httpservletrequest request ) { list<multipartfile> files = product.getimages(); list<string> filenames = new arraylist<string>(); log.info("files legnth: " + files.size()); log.info("name: " + product.getname()); }
and if form:
<form:form commandname="product" action="${newlistingform }" method="post" enctype="multipart/form-data"> <form:input path="name" type="text"/> <form:input path="images" type="file" multiple=""/> <input type="submit"> </form:form>
so able print out "name" in controller "files" has size of 1 regardless have selected file or not. have followed suggestion in link include common-fileupload , common-io, problem not fix.
in jsp use following
<form ation="your/path" enctype="multipart/form-data" method="post">
in controller use following
import org.springframework.web.multipart.multipartfile; import org.springframework.web.multipart.multiparthttpservletrequest; public string yourmethod(multiparthttpservletrequest request){ }
this should resolve problem
Comments
Post a Comment