PDA

View Full Version : Q: FileUpload with a AbstractWizardFormController


Dari
Oct 12th, 2007, 11:52 AM
I've got a problem.
i want to use a AbstractWizardFormController for a FileUpload. in the first page i want, that the User select the upload-file with:


<form:form method="post" name="fileUploadController" enctype="multipart/form-data" commandName="file" id="form">
Please select a file: <br>
<input type="file" name="file"/>
<br><br>
<!-- <input type="submit"/> -->
<fieldset class="evenLast">
<p class="submit"><input type="submit" alignment="center" name="_target1" value="Up to Step 2" /></p>
</fieldset>
</form:form>


then on the Next Page, the User have to fill in some different other fields like "title" or "description".


<form:form method="post" name="fileUploadController" commandName="file" id="form">

Title:<br>
<spring:bind path="file.title">
<!-- <input type="text" name="title" value="<c:out value="${status.value}"/>"/> -->
<input type="text" name="title" />
<font color="red"><c:out value="${status.errorMessage}"/> </font>
</spring:bind>
<br><br>
Description:<br>
<spring:bind path="file.description">
<textarea rows="15" cols="40" name="description" ></textarea><br>
<font color="red"><c:out value="${status.errorMessage}"/> </font>
</spring:bind>
<br><br>
<fieldset class="evenLast">
<p class="submit"><input type="submit" alignment="center" name="_target2" value="Up to Step 3" /></p>
</fieldset>
</form:form>


in the end the User have to accept all this stuff

<form:form method="post" action="upload1.htm" name="fileUploadController" commandName="file" id="form">
...
<input type="submit" align="middle" name="_finish" value="Execute Order" />
</form:form>


but when the User execute the Finish method
processFinish(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception

it shows this ErrorMessage:
java.lang.IllegalStateException: File has already been moved - cannot be transferred again
at org.springframework.web.multipart.commons.CommonsM ultipartFile.transferTo(CommonsMultipartFile.java: 128)
at com.xxx.web.FileUploadController.processFinish(Fil eUploadController.java:133)
at org.springframework.web.servlet.mvc.AbstractWizard FormController.validatePagesAndFinish(AbstractWiza rdFormController.java:650)
at org.springframework.web.servlet.mvc.AbstractWizard FormController.processFormSubmission(AbstractWizar dFormController.java:490)
at org.springframework.web.servlet.mvc.AbstractFormCo ntroller.handleRequestInternal(AbstractFormControl ler.java:250)
at org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(AbstractController.java:153)
at org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda pter.java:45)
at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:820)
at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:755)
at org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:396)
at org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:360)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)

this line contains this(media is my formbackingobject):
file.transferTo(new File(media.getPath()));

i know the problem is that the file has already been moved in the filesystem as is not available anymore for another transfer(java.lang.IllegalStateException)
when i set the Page, in which the user select the file, at the end it works. but i want that the User set the Upload file in the beginnen.

if somebody can solve this problem, i would be very very happy.
thank you very much in advance.

greetings