You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by mo...@physics.gmu.edu on 2003/05/02 18:56:17 UTC

File Upload Help

I am trying to do FileUpload from the client machine to the Server, here
is the JSP form that accepts the File

<html:form action="/action/createlist"   enctype="multipart/formdata">
..........
</html:form>

In the struts-config.xml i have the following things
In the form-beans section

<form-bean    name="createlistForm"
         type="cee.GEST.webapp.CreateListForm" >
   </form-bean>

In the global Forwards section
 <forward   name="createlist"          path="/list/createlist.jsp" />

In the action mappings section i have
 <action path="/action/createlist"
          type="cee.GEST.webapp.CreateListAction"
          name="createlistForm"
          scope="request"
          input="/list/createlist.jsp">
     </action>



In the Action class i have the following code

public class CreateListAction extends Action{
	 private Log log =
		  LogFactory.getLog("cee.GEST.webapp.action.CreateNewListAction");

	 public ActionForward execute(ActionMapping mapping,
											ActionForm form,
											HttpServletRequest request,
											HttpServletResponse response) throws Exception{

		  FileUpload fileupload = new FileUpload();
		  log.info(" Created File upload object");

		  List fileItems = fileupload.parseRequest(request);
		  log.info("got the list of files");
		  Iterator i = fileItems.iterator();
		  log.info("obtained an iterator");
		  FileItem fileitem = (FileItem)i.next();
		  log.info("Create a New File Item");
		  String fileName = fileitem.getName();
		  log.info("Got the filename and trying to Write to Server");
		  fileitem.write("/var/www/uploads/"+fileName);
		  log.info("successfully wrote to the Server");



		  return(mapping.findForward("showmessages"));
	 }

}



It looks like the mapping is not the problem but the problem is with JSPs
enctype being multipart/formdata.... and when i submit the JSP the JSP
needs to invoke a POST method and i am not sure what the struts action
class does but i get this error:

 No action instance for path /action/createlist could be created

description The server encountered an internal error (No action instance
for path /action/createlist could be created) that prevented it from
fulfilling this request.


Please help me out with this problem....


Thanx in advance

--Mohan






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


Re: File Upload Help

Posted by Robert Leland <rl...@apache.org>.
mohan@physics.gmu.edu wrote:
[Parts deleted]
> 
> public class CreateListAction extends Action{
> 	 private Log log =
> 		  LogFactory.getLog("cee.GEST.webapp.action.CreateNewListAction");
> 
> 	 public ActionForward execute(ActionMapping mapping,
> 											ActionForm form,
> 											HttpServletRequest request,
> 											HttpServletResponse response) throws Exception{
> 
> 		  FileUpload fileupload = new FileUpload();
> 		  log.info(" Created File upload object");
> 
> 		  List fileItems = fileupload.parseRequest(request);

I believe this will only work if you are using a servlet directly,
though I could be very very wrong.
We just use the struts wrappers for the Commons-fileupload.
See the struts-upload example code.

-Rob


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


Re: File Upload Help

Posted by mo...@physics.gmu.edu.
Thank you all guyz i have found the struts-upload.war file in there and i
am trying to read that now but my question is why is it not even
recognizing the Action class, it shud atleast reach the action class and
then give an error but it is saying cannot find an instance of that action
class....do i need any other configuration for file upload to work?????


--mohan


> mohan@physics.gmu.edu wrote:
>> Hi Dan Where can i find that resource you said...i dint know there is
>> one such i am completely new to struts...
>
> Download the source distribution at
> http://cvs.apache.org/builds/jakarta-struts/nightly/
>
> Download the latest build then
> go to
>
> src/upload/... for the example code.
>
> -Rob
>
>
>
>
>
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org For
> additional commands, e-mail: struts-user-help@jakarta.apache.org




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


Re: File Upload Help

Posted by Robert Leland <rl...@apache.org>.
mohan@physics.gmu.edu wrote:
> Hi Dan Where can i find that resource you said...i dint know there is one
> such i am completely new to struts...

Download the source distribution at
http://cvs.apache.org/builds/jakarta-struts/nightly/

Download the latest build then
go to

src/upload/... for the example code.

-Rob





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


Re: File Upload Help

Posted by Dan Tran <da...@hotmail.com>.
struts-upload.war is in the struts distribution.

http://jakarta.apache.com/struts

-Dan
----- Original Message ----- 
From: <mo...@physics.gmu.edu>
To: <st...@jakarta.apache.org>
Sent: Friday, May 02, 2003 10:20 AM
Subject: Re: File Upload Help


> Hi Dan Where can i find that resource you said...i dint know there is one
> such i am completely new to struts...
>
> --Mohan
>
>
>
>
> > Have you tried to step thru the struts-upload example?
> > It is quite a comprehensive learning resource.
> >
> > -Dan
> > ----- Original Message -----
> > From: <mo...@physics.gmu.edu>
> > To: <st...@jakarta.apache.org>
> > Sent: Friday, May 02, 2003 9:56 AM
> > Subject: File Upload Help
> >
> >
> >> I am trying to do FileUpload from the client machine to the Server,
> >> here is the JSP form that accepts the File
> >>
> >> <html:form action="/action/createlist"   enctype="multipart/formdata">
> >> ..........
> >> </html:form>
> >>
> >> In the struts-config.xml i have the following things
> >> In the form-beans section
> >>
> >> <form-bean    name="createlistForm"
> >>          type="cee.GEST.webapp.CreateListForm" >
> >>    </form-bean>
> >>
> >> In the global Forwards section
> >>  <forward   name="createlist"          path="/list/createlist.jsp" />
> >>
> >> In the action mappings section i have
> >>  <action path="/action/createlist"
> >>           type="cee.GEST.webapp.CreateListAction"
> >>           name="createlistForm"
> >>           scope="request"
> >>           input="/list/createlist.jsp">
> >>      </action>
> >>
> >>
> >>
> >> In the Action class i have the following code
> >>
> >> public class CreateListAction extends Action{
> >> private Log log =
> >>   LogFactory.getLog("cee.GEST.webapp.action.CreateNewListAction");
> >>
> >> public ActionForward execute(ActionMapping mapping,
> >> ActionForm form,
> >> HttpServletRequest request,
> >> HttpServletResponse response) throws Exception{
> >>
> >>   FileUpload fileupload = new FileUpload();
> >>   log.info(" Created File upload object");
> >>
> >>   List fileItems = fileupload.parseRequest(request);
> >>   log.info("got the list of files");
> >>   Iterator i = fileItems.iterator();
> >>   log.info("obtained an iterator");
> >>   FileItem fileitem = (FileItem)i.next();
> >>   log.info("Create a New File Item");
> >>   String fileName = fileitem.getName();
> >>   log.info("Got the filename and trying to Write to Server");
> >>   fileitem.write("/var/www/uploads/"+fileName);
> >>   log.info("successfully wrote to the Server");
> >>
> >>
> >>
> >>   return(mapping.findForward("showmessages"));
> >> }
> >>
> >> }
> >>
> >>
> >>
> >> It looks like the mapping is not the problem but the problem is with
> >> JSPs enctype being multipart/formdata.... and when i submit the JSP
> >> the JSP needs to invoke a POST method and i am not sure what the
> >> struts action class does but i get this error:
> >>
> >>  No action instance for path /action/createlist could be created
> >>
> >> description The server encountered an internal error (No action
> >> instance for path /action/createlist could be created) that prevented
> >> it from fulfilling this request.
> >>
> >>
> >> Please help me out with this problem....
> >>
> >>
> >> Thanx in advance
> >>
> >> --Mohan
> >>
> >>
> >>
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org For
> >> additional commands, e-mail: struts-user-help@jakarta.apache.org
> >>
> >>
> >
> > --------------------------------------------------------------------- To
> > unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org For
> > additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>

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


Re: File Upload Help

Posted by mo...@physics.gmu.edu.
Hi Dan Where can i find that resource you said...i dint know there is one
such i am completely new to struts...

--Mohan




> Have you tried to step thru the struts-upload example?
> It is quite a comprehensive learning resource.
>
> -Dan
> ----- Original Message -----
> From: <mo...@physics.gmu.edu>
> To: <st...@jakarta.apache.org>
> Sent: Friday, May 02, 2003 9:56 AM
> Subject: File Upload Help
>
>
>> I am trying to do FileUpload from the client machine to the Server,
>> here is the JSP form that accepts the File
>>
>> <html:form action="/action/createlist"   enctype="multipart/formdata">
>> ..........
>> </html:form>
>>
>> In the struts-config.xml i have the following things
>> In the form-beans section
>>
>> <form-bean    name="createlistForm"
>>          type="cee.GEST.webapp.CreateListForm" >
>>    </form-bean>
>>
>> In the global Forwards section
>>  <forward   name="createlist"          path="/list/createlist.jsp" />
>>
>> In the action mappings section i have
>>  <action path="/action/createlist"
>>           type="cee.GEST.webapp.CreateListAction"
>>           name="createlistForm"
>>           scope="request"
>>           input="/list/createlist.jsp">
>>      </action>
>>
>>
>>
>> In the Action class i have the following code
>>
>> public class CreateListAction extends Action{
>> private Log log =
>>   LogFactory.getLog("cee.GEST.webapp.action.CreateNewListAction");
>>
>> public ActionForward execute(ActionMapping mapping,
>> ActionForm form,
>> HttpServletRequest request,
>> HttpServletResponse response) throws Exception{
>>
>>   FileUpload fileupload = new FileUpload();
>>   log.info(" Created File upload object");
>>
>>   List fileItems = fileupload.parseRequest(request);
>>   log.info("got the list of files");
>>   Iterator i = fileItems.iterator();
>>   log.info("obtained an iterator");
>>   FileItem fileitem = (FileItem)i.next();
>>   log.info("Create a New File Item");
>>   String fileName = fileitem.getName();
>>   log.info("Got the filename and trying to Write to Server");
>>   fileitem.write("/var/www/uploads/"+fileName);
>>   log.info("successfully wrote to the Server");
>>
>>
>>
>>   return(mapping.findForward("showmessages"));
>> }
>>
>> }
>>
>>
>>
>> It looks like the mapping is not the problem but the problem is with
>> JSPs enctype being multipart/formdata.... and when i submit the JSP
>> the JSP needs to invoke a POST method and i am not sure what the
>> struts action class does but i get this error:
>>
>>  No action instance for path /action/createlist could be created
>>
>> description The server encountered an internal error (No action
>> instance for path /action/createlist could be created) that prevented
>> it from fulfilling this request.
>>
>>
>> Please help me out with this problem....
>>
>>
>> Thanx in advance
>>
>> --Mohan
>>
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org For
>> additional commands, e-mail: struts-user-help@jakarta.apache.org
>>
>>
>
> --------------------------------------------------------------------- To
> unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org For
> additional commands, e-mail: struts-user-help@jakarta.apache.org




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


Re: File Upload Help

Posted by Dan Tran <da...@hotmail.com>.
Have you tried to step thru the struts-upload example?
It is quite a comprehensive learning resource.

-Dan
----- Original Message ----- 
From: <mo...@physics.gmu.edu>
To: <st...@jakarta.apache.org>
Sent: Friday, May 02, 2003 9:56 AM
Subject: File Upload Help


> I am trying to do FileUpload from the client machine to the Server, here
> is the JSP form that accepts the File
> 
> <html:form action="/action/createlist"   enctype="multipart/formdata">
> ..........
> </html:form>
> 
> In the struts-config.xml i have the following things
> In the form-beans section
> 
> <form-bean    name="createlistForm"
>          type="cee.GEST.webapp.CreateListForm" >
>    </form-bean>
> 
> In the global Forwards section
>  <forward   name="createlist"          path="/list/createlist.jsp" />
> 
> In the action mappings section i have
>  <action path="/action/createlist"
>           type="cee.GEST.webapp.CreateListAction"
>           name="createlistForm"
>           scope="request"
>           input="/list/createlist.jsp">
>      </action>
> 
> 
> 
> In the Action class i have the following code
> 
> public class CreateListAction extends Action{
> private Log log =
>   LogFactory.getLog("cee.GEST.webapp.action.CreateNewListAction");
> 
> public ActionForward execute(ActionMapping mapping,
> ActionForm form,
> HttpServletRequest request,
> HttpServletResponse response) throws Exception{
> 
>   FileUpload fileupload = new FileUpload();
>   log.info(" Created File upload object");
> 
>   List fileItems = fileupload.parseRequest(request);
>   log.info("got the list of files");
>   Iterator i = fileItems.iterator();
>   log.info("obtained an iterator");
>   FileItem fileitem = (FileItem)i.next();
>   log.info("Create a New File Item");
>   String fileName = fileitem.getName();
>   log.info("Got the filename and trying to Write to Server");
>   fileitem.write("/var/www/uploads/"+fileName);
>   log.info("successfully wrote to the Server");
> 
> 
> 
>   return(mapping.findForward("showmessages"));
> }
> 
> }
> 
> 
> 
> It looks like the mapping is not the problem but the problem is with JSPs
> enctype being multipart/formdata.... and when i submit the JSP the JSP
> needs to invoke a POST method and i am not sure what the struts action
> class does but i get this error:
> 
>  No action instance for path /action/createlist could be created
> 
> description The server encountered an internal error (No action instance
> for path /action/createlist could be created) that prevented it from
> fulfilling this request.
> 
> 
> Please help me out with this problem....
> 
> 
> Thanx in advance
> 
> --Mohan
> 
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 

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