java - Spring mvc The current request is not a multipart request -


i error whenever try access "/uploadfile"

etat http 500 - request processing failed; nested exception org.springframework.web.multipart.multipartexception: current request not multipart request 

here method in controller

@requestmapping(value = "/uploadfile", method = requestmethod.get)     public @responsebody     string uploadfilehandler(string name,multipartfile file) {          if (!file.isempty()) {             try {                 byte[] bytes = file.getbytes();                  // creating directory store file                 string rootpath = system.getproperty("catalina.home");                 file dir = new file(rootpath + file.separator + "tmpfiles");                 if (!dir.exists())                     dir.mkdirs();                  // create file on server                 file serverfile = new file(dir.getabsolutepath()                         + file.separator + name);                 bufferedoutputstream stream = new bufferedoutputstream(                         new fileoutputstream(serverfile));                 stream.write(bytes);                 stream.close();                  logger.info("server file location="                         + serverfile.getabsolutepath());                  return "you uploaded file=" + name;             } catch (exception e) {                 return "you failed upload " + name + " => " + e.getmessage();             }         } else {             return "you failed upload " + name                     + " because file empty.";         }     } 

the jsp form

<form method="get" action="uploadfile" enctype="multipart/form-data">     file upload: <input type="file" name="file"><br />      name: <input type="text" name="name"><br /> <br />      <input type="submit" value="upload"> press here upload file! </form> 

and added web.xml

<listener>         <listener-class>org.springframework.web.multipart.commons.commonsmultipartresolver</listener-class>     </listener> 

what doing wrong here?any appreciated.

upload file http mine must application/form-data method must post

 <form method="post"  method = requestmethod.post 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -