You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Paranoid_Fabio <pa...@yahoo.it> on 2008/02/16 13:07:58 UTC

Form with upload

Hello. I have to implement a file upload. Togheter with it, the user have to
fill a form.
The form is like:


         title
         price
         image

The user should fill the "title" and "price" field, upload an image and
then, clicking a submit button, send the form parameters to the action. So
what I need to do upload the file first and to store the File object in the
action. The clicking submit all the other form parameters should be sent to
the same action.

I tried defining two different methods in the same action: execute() that is
the method called when the "submit" button of the form is clicked and
uploadImage() that is the method that should be called only to upload the
image. But I can't do these because if I specify:

<action name="ManualContentUpload"
class="actions.contents.upload.ManualUpload">
        <result name="success">/pages/ManualContentUpload.jsp</result>
</action>

and:

<action name="ManualImageUpload"
class="actions.contents.upload.ManualUpload" method="doImageUpload">
        <result name="success">/pages/ManualContentUpload.jsp</result>
        <result name="input">/pages/ManualContentUpload.jsp</result>
</action>

(the same action class with doImageUpload() executed instead of execute())

And then in JSP

<form action=ManualImageUpload  method="POST" enctype="multipart/form-data">
     <input type="file" name="image" title="upload image"/>
     <input type="submit"/>
 </form>  	

it does not work. And the same thing if I create another action (action name
and class) and use it to upload only the image like that:

<form action=imageUploadAction  method="POST" enctype="multipart/form-data">
     <input type="file" name="image" title="upload image"/>
     <input type="submit"/>
 </form>  	

where imageUploadAction is a regular action (different from the one called
to display current jsp)

<action name=imageUploadAction" class="actions.contents.upload.ImageUpload"> 
        <result name="success">/pages/ManualContentUpload.jsp</result>
        <result name="input">/pages/ManualContentUpload.jsp</result>
</action>

Anyone can help me? thank you very much in advance.


-- 
View this message in context: http://www.nabble.com/Form-with-upload-tp15517551p15517551.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Form with upload

Posted by Dave Newton <ne...@yahoo.com>.
--- Paranoid_Fabio <pa...@yahoo.it> wrote:
> Thank you. If I submit all the data in "one shot" everything goes ok.
> 
> What I wanted to do in principle was to first upload the image (and other
> files the user has to upload), then submit the form with other parameters.
> like a step-by-step submission.
> The problem is that i would like to have, in the end, all the data (image,
> files, paramaters) available in the same action.. so what I thought to do
> is
> to call different methods of the same action class via different action
> names in struts.xml, each declaring a different <method> parameter..but I
> guess I'm doing something wrong.

S2 actions are instantiated for each request. If you want some sort of
wizard-like interface, where the form is filled in across several pages,
you'll need to keep some information in the session or in hidden form fields
etc.

Dave


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


Re: Form with upload

Posted by Paranoid_Fabio <pa...@yahoo.it>.
Thank you. If I submit all the data in "one shot" everything goes ok.

What I wanted to do in principle was to first upload the image (and other
files the user has to upload), then submit the form with other parameters.
like a step-by-step submission.
The problem is that i would like to have, in the end, all the data (image,
files, paramaters) available in the same action.. so what I thought to do is
to call different methods of the same action class via different action
names in struts.xml, each declaring a different <method> parameter..but I
guess I'm doing something wrong.


Paranoid_Fabio wrote:
> 
> Hello. I have to implement a file upload. Togheter with it, the user have
> to fill a form.
> The form is like:
> 
> 
>          title
>          price
>          image
> 
> The user should fill the "title" and "price" field, upload an image and
> then, clicking a submit button, send the form parameters to the action. So
> what I need is to do upload the file first and to store the File object in
> the action. Then clicking submit all the other form parameters should be
> sent to the same action.
> 
> I tried defining two different methods in the same action: execute() that
> is the method called when the "submit" button of the form is clicked and
> uploadImage() that is the method that should be called only to upload the
> image. But I can't do these because if I specify:
> 
> <action name="ManualContentUpload"
> class="actions.contents.upload.ManualUpload">
>         <result name="success">/pages/ManualContentUpload.jsp</result>
> </action>
> 
> and:
> 
> <action name="ManualImageUpload"
> class="actions.contents.upload.ManualUpload" method="doImageUpload">
>         <result name="success">/pages/ManualContentUpload.jsp</result>
>         <result name="input">/pages/ManualContentUpload.jsp</result>
> </action>
> 
> (the same action class with doImageUpload() executed instead of execute())
> 
> And then in JSP
> 
> <form action=ManualImageUpload  method="POST"
> enctype="multipart/form-data">
>      <input type="file" name="image" title="upload image"/>
>      <input type="submit"/>
>  </form>  	
> 
> it does not work. And the same thing if I create another action (action
> name and class) and use it to upload only the image like that:
> 
> <form action=imageUploadAction  method="POST"
> enctype="multipart/form-data">
>      <input type="file" name="image" title="upload image"/>
>      <input type="submit"/>
>  </form>  	
> 
> where imageUploadAction is a regular action (different from the one called
> to display current jsp)
> 
> <action name=imageUploadAction"
> class="actions.contents.upload.ImageUpload"> 
>         <result name="success">/pages/ManualContentUpload.jsp</result>
>         <result name="input">/pages/ManualContentUpload.jsp</result>
> </action>
> 
> Anyone can help me? thank you very much in advance.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Form-with-upload-tp15517551p15518224.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Form with upload

Posted by Paranoid_Fabio <pa...@yahoo.it>.
ok. I've understood. Thank you very much


Paranoid_Fabio wrote:
> 
> Hello. I have to implement a file upload. Togheter with it, the user have
> to fill a form.
> The form is like:
> 
> 
>          title
>          price
>          image
> 
> The user should fill the "title" and "price" field, upload an image and
> then, clicking a submit button, send the form parameters to the action. So
> what I need is to do upload the file first and to store the File object in
> the action. Then clicking submit all the other form parameters should be
> sent to the same action.
> 
> I tried defining two different methods in the same action: execute() that
> is the method called when the "submit" button of the form is clicked and
> uploadImage() that is the method that should be called only to upload the
> image. But I can't do these because if I specify:
> 
> <action name="ManualContentUpload"
> class="actions.contents.upload.ManualUpload">
>         <result name="success">/pages/ManualContentUpload.jsp</result>
> </action>
> 
> and:
> 
> <action name="ManualImageUpload"
> class="actions.contents.upload.ManualUpload" method="doImageUpload">
>         <result name="success">/pages/ManualContentUpload.jsp</result>
>         <result name="input">/pages/ManualContentUpload.jsp</result>
> </action>
> 
> (the same action class with doImageUpload() executed instead of execute())
> 
> And then in JSP
> 
> <form action=ManualImageUpload  method="POST"
> enctype="multipart/form-data">
>      <input type="file" name="image" title="upload image"/>
>      <input type="submit"/>
>  </form>  	
> 
> it does not work. And the same thing if I create another action (action
> name and class) and use it to upload only the image like that:
> 
> <form action=imageUploadAction  method="POST"
> enctype="multipart/form-data">
>      <input type="file" name="image" title="upload image"/>
>      <input type="submit"/>
>  </form>  	
> 
> where imageUploadAction is a regular action (different from the one called
> to display current jsp)
> 
> <action name=imageUploadAction"
> class="actions.contents.upload.ImageUpload"> 
>         <result name="success">/pages/ManualContentUpload.jsp</result>
>         <result name="input">/pages/ManualContentUpload.jsp</result>
> </action>
> 
> Anyone can help me? thank you very much in advance.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Form-with-upload-tp15517551p15518630.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Form with upload

Posted by Dave Newton <ne...@yahoo.com>.
--- Paranoid_Fabio <pa...@yahoo.it> wrote:
> Hello. I have to implement a file upload. Togheter with it, the user have
> to fill a form.
> The form is like:
> 
> 
>          title
>          price
>          image
> 
> The user should fill the "title" and "price" field, upload an image and
> then, clicking a submit button, send the form parameters to the action. So
> what I need to do upload the file first and to store the File object in the
> action. The clicking submit all the other form parameters should be sent to
> the same action.

You seem to say two different things in your email.

Do you want the title and price fields to be on the same JSP page as your
image or not?

The file upload occurs on form submission; it's not separate from the rest of
the form. If you want two form pages then just make two form pages, if not
then you don't need to do anything special.

Dave


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