ERLEDIGT
NEIN
NEIN
ANTWORTEN
3
3
ZUGRIFFE
1491
1491
EMPFEHLEN
-
Hi,
ich hab mir jetzt schon wirklich alle Sachen zum FileUpload in Spring durchgelesen, aber bei mir funktioniert er nicht so, wie er sollte. Meine Backingbean ist immer null!
xml:
Code :1 2 3 4 5 6 7 8 9 10
<bean id="documentManagementUploadController" class="de.etss.core.mvc.controller.administration.documentmanagement.DocumentManagementUploadController"> <property name="commandClass" value="de.etss.core.mvc.forms.DocumentManagementUploadForm" /> <property name="commandName" value="MyCommand"/> <property name="formView" value="documentmanagementupload"/> <property name="successView" value="documentmanagementshow"/> </bean> <bean id="multiPartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" > <property name="maxUploadSize" value="100000"/> </bean>
Das Formular zum Upload
Der ControllerHTML-Code:<%@ page language="java"%> <%@ include file="/jsp/include.jsp"%> <form:form method="post" commandName="MyCommand" enctype="multipart/form-data"> <table> <tr> <td><input type="file" name="file" /></td> <td><input type="submit" value='<spring:message code="button.speichern"/>'></td> </tr> </table> </form:form>
Code :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
package de.etss.core.mvc.controller.administration.documentmanagement; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.springframework.validation.BindException; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.SimpleFormController; import de.etss.core.mvc.forms.DocumentManagementUploadForm; public class DocumentManagementUploadController extends SimpleFormController { private static final Logger logger = Logger.getLogger(DocumentManagementUploadController.class); @Override protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { DocumentManagementUploadForm form = (DocumentManagementUploadForm)command; MultipartFile file = form.getFile(); if(null == file) { logger.error("No File was uploaded!"); } else { logger.info("Do some stuff with file"); } return new ModelAndView(getSuccessView()); } @Override protected Object formBackingObject(HttpServletRequest request) throws Exception { DocumentManagementUploadForm form = new DocumentManagementUploadForm(null); return form; } }
Die Bean
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
package de.etss.core.mvc.forms; import org.springframework.web.multipart.MultipartFile; public class DocumentManagementUploadForm { private MultipartFile file; public DocumentManagementUploadForm(MultipartFile file) { this.file = file; } public MultipartFile getFile() { return file; } public void setFile(MultipartFile file) { this.file = file; } }
Es funktioniert nur, wenn ich dem Controller den MultiPartResolver injiziere und mir dann darüber das File besorge. Ich würde es aber gerne so wie in der Spring-Doku machen. Vielleicht wißt ihr ja eine Lösung.
Grüße,
Peter
-
14.11.08 12:34 #2
Meine Springdoku (http://static.springframework.org/sp...#mvc-multipart) sagt: Multipart Binder per initBinder registrieren und im Formularobjekt ein byte-Array benutzen...
Gruß
OllieIn theory, there is no difference between theory and practice. In practice, there is!
www.olivergierke.de
-
Hi Olli,
das hab ich auch schon versucht, geht aber auch nicht.
Außerdem will ich das MultiPartFile so, wie es ist und nicht erst einen PropertyEditor registrieren.
Grüße
Peter
-
Das Problem scheint an Spring Security zu liegen, insbesondere am SavedRequestAwareWrapper:
http://www.acegisecurity.org/acegi-s...reWrapper.html
Ähnliche Themen
-
JAVA HTTP multipart Post funktioniert nicht
Von kriizz im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 0Letzter Beitrag: 23.04.10, 16:53 -
Javamail: Content von multipart/MIXED wird nicht angezeigt
Von magic_halli im Forum JavaAntworten: 1Letzter Beitrag: 28.03.08, 07:03 -
Fileupload will einfach nicht mehr klappen
Von jasoeight im Forum PHPAntworten: 2Letzter Beitrag: 06.11.07, 23:51 -
Problem mit Fileupload (speichert Files nicht)
Von shadow2 im Forum PHPAntworten: 10Letzter Beitrag: 14.06.07, 16:27 -
HibernateTemplate().save() aus dem Spring-Framework funktioniert nicht..
Von mahosand im Forum Enterprise Java (JEE, J2EE, Spring & Co.)Antworten: 4Letzter Beitrag: 28.12.06, 16:00





Zitieren
Login





