You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by ryan webb <we...@gmail.com> on 2008/11/20 07:23:59 UTC

Struts 2: What do i need to do to be able to upload files

Hello, first I would like to thank you for reading my email.

I am trying out some examples for uploading a file.  And I always get HTTP
500 error from tomcat.
I can't see why, I followed and copied the example.  For sure I missed
something but I don't know what?
I tried debugging but I failed because IDE don't enter the execute() method.

*The error is:*
java.lang.RuntimeException: Unable to load bean
org.apache.struts2.dispatcher.multipart.MultiPartRequest (jakarta) -
[unknown location]

do need do extra configurations?  please help?


*here's my JSP:*
<%@page language="java" contentType="text/html; charset=ISO-8859-1"%>
<%@taglib prefix="s" uri="/struts-tags"%>

<html>
    <head>
    <title>Ryan file upload</title>
    </head>
    <body>
        *<s:form action="upload" method="post"
enctype="multipart/form-data">*
            <s:file name="file" label="File" />
            <s:submit />
        *</s:form>*
    </body>
</html>

*here's my Action:*
*package* manning.ryan;

*import* java.io.File;
*import* java.io.IOException;

*import* com.opensymphony.xwork2.ActionSupport;

*public class* UploadAction *extends* ActionSupport {

    @Override
    *public* String *execute*() {
        *try* {
            getUploadService().uploadFile(getFile(), getFileName(),
getFileSystemPath());
        } *catc**h* (IOException e) {
            e.printStackTrace();
        }
        *return* *SUCCESS*;
    }

    /* File Upload JavaBeans */
    File file;
    String fileContentType;
    String fileSystemPath;
    String fileName;

    *public* File getFile() {
        *return *file;
    }

    *public* *void* setFile(File file) {
        *this*.file = file;
    }

    *public* String getFileContentType() {

        *return *fileContentType;
    }

    *public* *void* setFileContentType(String fileContentType) {
        *this*.fileContentType = fileContentType;
    }

    *public* String getFileSystemPath() {
        *return *fileSystemPath;
    }

    *public* *void* setFileSystemPath(String fileSystemPath) {
        *this*.fileSystemPath = fileSystemPath;
    }

    *public* String getFileName() {
        *return *fileName;
    }

    *public* *void* setFileName(String fileName) {
        *this*.fileName = fileName;
    }

    *public* UploadService getUploadService() {
        *return *new UploadService();
    }
}

*here's my UploadService.java:*
*package *manning.ryan;

*import* java.io.File;
*import* java.io.FileInputStream;
*import* java.io.FileOutputStream;
*import* java.io.IOException;

*public class* UploadService {

    *public* *void* *uploadFile*(*File* file, *String* fileName,
*String*fileSystemPath)
*throws* IOException {
        FileInputStream in = *null*;
        FileOutputStream out = *null*;

        String folderName = fileSystemPath;
        File dir = *new* File(folderName);

        *if* (!dir.exists()) {
            dir.mkdir();
        }

        String targetPath = dir.getPath() + dir.*separator* + fileName;
        System.*out*.println("writing file to " + targetPath);

        File fileDestination = *new* File(targetPath);

        *try* {
            in = new FileInputStream(file);
            out = new FileOutputStream(fileDestination);

            *int* i;
            *while*((i = in.read()) != -1) {
                out.write(i);
            }
        } *finally* {
            *if* (out != *null*) out.close();
            *if* (in != *null*) in.close();
        }

    }
}


*here's my struts-config:*
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <package name="ryan" namespace="/ryan" extends="struts-default">
        <action name="addFile">
            <result>
                /ryan/ryan.jsp
            </result>
        </action>

        <action name="upload" class="manning.ryan.UploadAction">
            <param name="fileSystemPath">./myFiles/</param>
            <result>/ryan/uploadSuccess.jsp</result>
            <result name="input">/ryan/ryan.jsp</result>
        </action>
    </package>
</struts>

-- 
warmest regards,
Ryan Webb - Philippines

email: webb.ryan1@gmail.com

RE: Struts 2: What do i need to do to be able to upload files

Posted by "Peterson, Ryan" <Ry...@McKesson.com>.
Check here:
http://struts.apache.org/2.0.6/docs/how-do-we-upload-files.html

Specifically the struts.multipart.maxSize property.

-----Original Message-----
From: ryan webb [mailto:webb.ryan1@gmail.com] 
Sent: Thursday, November 20, 2008 4:53 PM
To: Struts Users Mailing List
Subject: Re: Struts 2: What do i need to do to be able to upload files

By the way, is there a file size limit for uploading files?  I tried to
upload 600+MB of movie and it just failed!
What can you say 'bout this?

On Fri, Nov 21, 2008 at 7:22 AM, ryan webb <we...@gmail.com> wrote:

> Hi I finally got it!
> Three request parameters are by default to uploading files to struts 2
>
> -the file itself
> -the content type and
> -the filename
>
> Frame work is expecting some correct methods like the one you
suggested.
> It's uploading now. Thank you very much your reply, and your time.  It
has
> been very helpful.
>
> God bless.
>
>
> On Thu, Nov 20, 2008 at 7:10 PM, Jeromy Evans <
> jeromy.evans@blueskyminds.com.au> wrote:
>
>> ryan webb wrote:
>>
>>> Thanks for your kind reply but I have commons-fileupload-1.1.1.jar
and
>>> commons-io-1.2.jar in my lib folder.  With those jar files included,
>>> doesn't
>>> that mean that I should be able to do file uploads automatcally?
>>>
>>>
>>>
>>
>> Yes.  The "unable to load bean MultiPartRequest  (jakarta)" message
>> implies there's still a configuration problem though.  Is there a
"caused
>> by" in the stack trace?
>>
>> You must be very close.  Can you change the name of your file field
to
>> something else, say "upload".
>> Your action should then have the setters:
>>  void setUpload(File file);
>>  void setUploadFileName(String fileName);
>>  void setUploadContentType(String contentType);
>>
>> That's slightly different than your quoted configuration (as calling
the
>> File "file" implies there should be a setFileFileName method).  That
>> shouldn't cause a 500 error though.
>>
>>
>>  On Thu, Nov 20, 2008 at 2:56 PM, Jeromy Evans <
>>> jeromy.evans@blueskyminds.com.au> wrote:
>>>
>>>
>>>
>>>> ryan webb wrote:
>>>>
>>>>
>>>>
>>>>> Hello, first I would like to thank you for reading my email.
>>>>>
>>>>> I am trying out some examples for uploading a file.  And I always
get
>>>>> HTTP
>>>>> 500 error from tomcat.
>>>>> I can't see why, I followed and copied the example.  For sure I
missed
>>>>> something but I don't know what?
>>>>> I tried debugging but I failed because IDE don't enter the
execute()
>>>>> method.
>>>>>
>>>>>
>>>>>
>>>>>
>>>> Ensure you have included the "add on" dependencies described here:
>>>>
>>>> http://struts.apache.org/2.x/docs/file-upload.html
>>>>
>>>> There are good examples and explanations for Struts 2.0.x and 2.1.x
on
>>>> that
>>>> page.
>>>>
>>>>
>>>>
>>>>
---------------------------------------------------------------------
>>>> 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
>>
>>
>
>
> --
> warmest regards,
> Ryan Webb - Philippines
>
> email: webb.ryan1@gmail.com
>
>
>


-- 
warmest regards,
Ryan Webb - Philippines

email: webb.ryan1@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts 2: What do i need to do to be able to upload files

Posted by ryan webb <we...@gmail.com>.
By the way, is there a file size limit for uploading files?  I tried to
upload 600+MB of movie and it just failed!
What can you say 'bout this?

On Fri, Nov 21, 2008 at 7:22 AM, ryan webb <we...@gmail.com> wrote:

> Hi I finally got it!
> Three request parameters are by default to uploading files to struts 2
>
> -the file itself
> -the content type and
> -the filename
>
> Frame work is expecting some correct methods like the one you suggested.
> It's uploading now. Thank you very much your reply, and your time.  It has
> been very helpful.
>
> God bless.
>
>
> On Thu, Nov 20, 2008 at 7:10 PM, Jeromy Evans <
> jeromy.evans@blueskyminds.com.au> wrote:
>
>> ryan webb wrote:
>>
>>> Thanks for your kind reply but I have commons-fileupload-1.1.1.jar and
>>> commons-io-1.2.jar in my lib folder.  With those jar files included,
>>> doesn't
>>> that mean that I should be able to do file uploads automatcally?
>>>
>>>
>>>
>>
>> Yes.  The "unable to load bean MultiPartRequest  (jakarta)" message
>> implies there's still a configuration problem though.  Is there a "caused
>> by" in the stack trace?
>>
>> You must be very close.  Can you change the name of your file field to
>> something else, say "upload".
>> Your action should then have the setters:
>>  void setUpload(File file);
>>  void setUploadFileName(String fileName);
>>  void setUploadContentType(String contentType);
>>
>> That's slightly different than your quoted configuration (as calling the
>> File "file" implies there should be a setFileFileName method).  That
>> shouldn't cause a 500 error though.
>>
>>
>>  On Thu, Nov 20, 2008 at 2:56 PM, Jeromy Evans <
>>> jeromy.evans@blueskyminds.com.au> wrote:
>>>
>>>
>>>
>>>> ryan webb wrote:
>>>>
>>>>
>>>>
>>>>> Hello, first I would like to thank you for reading my email.
>>>>>
>>>>> I am trying out some examples for uploading a file.  And I always get
>>>>> HTTP
>>>>> 500 error from tomcat.
>>>>> I can't see why, I followed and copied the example.  For sure I missed
>>>>> something but I don't know what?
>>>>> I tried debugging but I failed because IDE don't enter the execute()
>>>>> method.
>>>>>
>>>>>
>>>>>
>>>>>
>>>> Ensure you have included the "add on" dependencies described here:
>>>>
>>>> http://struts.apache.org/2.x/docs/file-upload.html
>>>>
>>>> There are good examples and explanations for Struts 2.0.x and 2.1.x on
>>>> that
>>>> page.
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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
>>
>>
>
>
> --
> warmest regards,
> Ryan Webb - Philippines
>
> email: webb.ryan1@gmail.com
>
>
>


-- 
warmest regards,
Ryan Webb - Philippines

email: webb.ryan1@gmail.com

Re: Struts 2: What do i need to do to be able to upload files

Posted by ryan webb <we...@gmail.com>.
Hi I finally got it!
Three request parameters are by default to uploading files to struts 2

-the file itself
-the content type and
-the filename

Frame work is expecting some correct methods like the one you suggested.
It's uploading now. Thank you very much your reply, and your time.  It has
been very helpful.

God bless.

On Thu, Nov 20, 2008 at 7:10 PM, Jeromy Evans <
jeromy.evans@blueskyminds.com.au> wrote:

> ryan webb wrote:
>
>> Thanks for your kind reply but I have commons-fileupload-1.1.1.jar and
>> commons-io-1.2.jar in my lib folder.  With those jar files included,
>> doesn't
>> that mean that I should be able to do file uploads automatcally?
>>
>>
>>
>
> Yes.  The "unable to load bean MultiPartRequest  (jakarta)" message implies
> there's still a configuration problem though.  Is there a "caused by" in the
> stack trace?
>
> You must be very close.  Can you change the name of your file field to
> something else, say "upload".
> Your action should then have the setters:
>  void setUpload(File file);
>  void setUploadFileName(String fileName);
>  void setUploadContentType(String contentType);
>
> That's slightly different than your quoted configuration (as calling the
> File "file" implies there should be a setFileFileName method).  That
> shouldn't cause a 500 error though.
>
>
>  On Thu, Nov 20, 2008 at 2:56 PM, Jeromy Evans <
>> jeromy.evans@blueskyminds.com.au> wrote:
>>
>>
>>
>>> ryan webb wrote:
>>>
>>>
>>>
>>>> Hello, first I would like to thank you for reading my email.
>>>>
>>>> I am trying out some examples for uploading a file.  And I always get
>>>> HTTP
>>>> 500 error from tomcat.
>>>> I can't see why, I followed and copied the example.  For sure I missed
>>>> something but I don't know what?
>>>> I tried debugging but I failed because IDE don't enter the execute()
>>>> method.
>>>>
>>>>
>>>>
>>>>
>>> Ensure you have included the "add on" dependencies described here:
>>>
>>> http://struts.apache.org/2.x/docs/file-upload.html
>>>
>>> There are good examples and explanations for Struts 2.0.x and 2.1.x on
>>> that
>>> page.
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>
>


-- 
warmest regards,
Ryan Webb - Philippines

email: webb.ryan1@gmail.com

Re: Struts 2: What do i need to do to be able to upload files

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
ryan webb wrote:
> Thanks for your kind reply but I have commons-fileupload-1.1.1.jar and
> commons-io-1.2.jar in my lib folder.  With those jar files included, doesn't
> that mean that I should be able to do file uploads automatcally?
>
>   

Yes.  The "unable to load bean MultiPartRequest  (jakarta)" message 
implies there's still a configuration problem though.  Is there a 
"caused by" in the stack trace?

You must be very close.  Can you change the name of your file field to 
something else, say "upload".
Your action should then have the setters:
  void setUpload(File file);
  void setUploadFileName(String fileName);
  void setUploadContentType(String contentType);

That's slightly different than your quoted configuration (as calling the 
File "file" implies there should be a setFileFileName method).  That 
shouldn't cause a 500 error though.

> On Thu, Nov 20, 2008 at 2:56 PM, Jeromy Evans <
> jeromy.evans@blueskyminds.com.au> wrote:
>
>   
>> ryan webb wrote:
>>
>>     
>>> Hello, first I would like to thank you for reading my email.
>>>
>>> I am trying out some examples for uploading a file.  And I always get HTTP
>>> 500 error from tomcat.
>>> I can't see why, I followed and copied the example.  For sure I missed
>>> something but I don't know what?
>>> I tried debugging but I failed because IDE don't enter the execute()
>>> method.
>>>
>>>
>>>       
>> Ensure you have included the "add on" dependencies described here:
>>
>> http://struts.apache.org/2.x/docs/file-upload.html
>>
>> There are good examples and explanations for Struts 2.0.x and 2.1.x on that
>> page.
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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: Struts 2: What do i need to do to be able to upload files

Posted by ryan webb <we...@gmail.com>.
Thanks for your kind reply but I have commons-fileupload-1.1.1.jar and
commons-io-1.2.jar in my lib folder.  With those jar files included, doesn't
that mean that I should be able to do file uploads automatcally?


On Thu, Nov 20, 2008 at 2:56 PM, Jeromy Evans <
jeromy.evans@blueskyminds.com.au> wrote:

> ryan webb wrote:
>
>> Hello, first I would like to thank you for reading my email.
>>
>> I am trying out some examples for uploading a file.  And I always get HTTP
>> 500 error from tomcat.
>> I can't see why, I followed and copied the example.  For sure I missed
>> something but I don't know what?
>> I tried debugging but I failed because IDE don't enter the execute()
>> method.
>>
>>
>
> Ensure you have included the "add on" dependencies described here:
>
> http://struts.apache.org/2.x/docs/file-upload.html
>
> There are good examples and explanations for Struts 2.0.x and 2.1.x on that
> page.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
warmest regards,
Ryan Webb - Philippines

email: webb.ryan1@gmail.com

Re: Struts 2: What do i need to do to be able to upload files

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
ryan webb wrote:
> Hello, first I would like to thank you for reading my email.
>
> I am trying out some examples for uploading a file.  And I always get HTTP
> 500 error from tomcat.
> I can't see why, I followed and copied the example.  For sure I missed
> something but I don't know what?
> I tried debugging but I failed because IDE don't enter the execute() method.
>   

Ensure you have included the "add on" dependencies described here:

http://struts.apache.org/2.x/docs/file-upload.html

There are good examples and explanations for Struts 2.0.x and 2.1.x on 
that page.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org