You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Erik Weber <er...@mindspring.com> on 2004/08/08 12:37:33 UTC
File upload problem
A colleague gave me a nice file upload Servlet to use; it uses the
jakarta commons file upload classes.
I am trying to convert it to a Struts Action class.
Converting the Servlet's doPost method to work in the Action class has
not been a problem. The problem is with the source JSP.
If I use html:form/html:file in the source JSP, the upload does not work
-- DiskFileUpload.parseRequest returns zero FileItems.
<!-- doesn't work -->
<html:form action="/upload" enctype="multipart/form-data">
<html:file property="theFile"/>
</html:form>
Even if I change the html:file tag to a regular HTML input tag, and use
a form bean that is just an empty class, it still doesn't work.
<!-- doesn't work -->
<html:form action="/upload" enctype="multipart/form-data">
<input type="file" name="theFile"/>
</html:form>
If I change the html:form tag to be a regular HTML form tag, and change
my struts-config action mapping so that it doesn't associate a form bean
at all, everything works -- DiskFileUpload.parseRequest now returns 1
FileItem.
<!-- combined with a no-form action, works -->
<form action="/context/upload" method="POST" enctype="multipart/form-data">
<input type="file" name="theFile"/>
</form>
I assume that using a form bean at all is screwing this up, but I'm
perhaps too tired to understand why. I couldn't really surmise by
looking at the upload example that comes with Struts, as it appears to
use a different technique for the upload implementation (not
DiskFileUpload, etc.).
How can I make the source JSP work with my Action class and at the same
time use the struts tags and an associated form bean, so that I can take
advantage of validation, etc.?
Thanks,
Erik
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: File upload problem
Posted by Erik Weber <er...@mindspring.com>.
Well the idea was to save time, since the upload Servlet already was
working.
I think I see the connection now -- it seems that FormFile is where the
Commons implementation is lurking, whereas the Servlet works directly
with FileItem objects. It is tough to make the connection to Commons
FileUpload just by looking at those Struts examples, and I didn't want
to reimplement features that DiskFileUpload gave me (such as the memory
management/tmp dir). So I was trying to figure out how to use FormFile
in my form, but somehow work with DiskFileUpload in myAction class.
Probably not worth the trouble (but someone please let me know if you
have done this or if there is a good reason to). I'll try handling the
input stream myself with FormFile as the example shows. But that Commons
FileUpload API is nice to work with.
Thanks,
Erik
Craig McClanahan wrote:
>On Sun, 08 Aug 2004 06:37:33 -0400, Erik Weber <er...@mindspring.com> wrote:
>
>
>
>>A colleague gave me a nice file upload Servlet to use; it uses the
>>jakarta commons file upload classes.
>>
>>
>
>Is there a particular reason that you're not using the standard Struts
>support for file upload (also based on Commons FileUpload but already
>integrated into Struts)? The "struts-upload.war" (Struts 1.1) or
>"struts-examples.war" (Struts 1.2) webapp contains examples of using
>this feature.
>
>Craig
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: File upload problem
Posted by Axel Stahlhut <as...@neusta.de>.
Craig McClanahan wrote:
> On Sun, 08 Aug 2004 06:37:33 -0400, Erik Weber <er...@mindspring.com> wrote:
>
>
>>A colleague gave me a nice file upload Servlet to use; it uses the
>>jakarta commons file upload classes.
>
>
> Is there a particular reason that you're not using the standard Struts
> support for file upload (also based on Commons FileUpload but already
> integrated into Struts)? The "struts-upload.war" (Struts 1.1) or
> "struts-examples.war" (Struts 1.2) webapp contains examples of using
> this feature.
>
> Craig
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
Hi,
with tha i always get a "duplicate entry in classpath" error when tomcat
is loading the context (jdk 1.4.04). Does anybody know why?
regards axel
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: File upload problem
Posted by Craig McClanahan <cr...@gmail.com>.
On Sun, 08 Aug 2004 06:37:33 -0400, Erik Weber <er...@mindspring.com> wrote:
> A colleague gave me a nice file upload Servlet to use; it uses the
> jakarta commons file upload classes.
Is there a particular reason that you're not using the standard Struts
support for file upload (also based on Commons FileUpload but already
integrated into Struts)? The "struts-upload.war" (Struts 1.1) or
"struts-examples.war" (Struts 1.2) webapp contains examples of using
this feature.
Craig
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org