J'ai le meme code que toi mais toujours la meme erreur
1 2 3 4 5 6 7 8 9 10 11 12 13
| java.lang.NoSuchMethodError: org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(Lorg/apache/commons/fileupload/RequestContext;)Ljava/util/List;
org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
com.cmsspring.document.controller.TexteAddFormController.onSubmit(TexteAddFormController.java:66)
org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:267)
org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:250)
org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:857)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:792)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:475)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:440)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802) |
voici le code de mon controlleur
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors) throws Exception {
logger.info("Entering controller");
Texte texte = (Texte)command;
texte.setTaille(1);
texte.setId(1);
//recupération du fichier
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if(!isMultipart){
System.out.println("pas multipart");
}
// Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Set upload parameters
// See Apache Commons FileUpload for more information
// http://jakarta.apache.org/commons/fileupload/using.html
upload.setSizeMax(-1);
try {
String directory = "";
// Parse the request
List items = upload.parseRequest(request);
// Process the uploaded items
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
// the param tag directory is sent as a request parameter to
// the server
// check if the upload directory is available
if (item.isFormField())
{String name = item.getFieldName();
System.out.println("- "+item.getString()+item.getFieldName());
//System.out.println("- "+request.getAttribute("option"));
if(name.equalsIgnoreCase("directory"))
{directory = item.getString();}
// retrieve the files
}
else
{// nommage du fichier
//System.out.println(item.getString()); //affiche le fichier
String fileName = item.getName();
File file = new File(fileName);
file = new File(BASE_DIRECTORY, file.getName());
//enregistremen dans /tmp/ si non vide
if(item.getInputStream().read()>-1)
{item.write(file);
session.setAttribute("file", file.getPath());}
}
}
} catch (Exception e) {
e.printStackTrace();
// response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
// fin recuperation
logger.info("Received : File Texte " + texte.getTitre() + " ");
//texteService.saveTexte(texte);
logger.info("Returning from UserAddFormController view to " + getSuccessView());
return new ModelAndView(new RedirectView(getSuccessView()));
} |
l'erreur est sur cette ligne
List items = upload.parseRequest(request);
je ne comprend pas pourquoi?
je suis dans un classe java.
quelqu'un a une idée
Partager