You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Manos Batsis <ma...@geekologue.com> on 2007/02/18 19:47:54 UTC
New MD4J tutorial and template, help in supporting S2 needed :-)
MD4J is an extensible J2EE webapp generator. One of the main features is
that it allows you to work on your model iteratively, providing a
complete J2EE application following your model changes. So, each time
you edit your model and build your project, MD4J will generate high
quality code from JSPs and Struts classes, to Session EJBs and DAOs,
allowing you to test CRUD and Search functionality on top of your model
right away.
The project allows pluggable generators, with the existing set
supporting EJB 2.1, Struts 1.x and JSP 2.0 as output for CRUD and Search
operations. I intent to add one for Struts 2 but i haven't used the
framework yet. If people in this list could suggest Struts 2 equivalents
of the Struts code listings presented in the tutorial, it would be a
great step towards a generator.
A new snapshot of the core along with a project template
(md4j-quickstarter) is available for download [1], along with a ten
minute tutorial dratf at [2]. The source [3] is available under the GPL.
[1] http://sourceforge.net/project/showfiles.php?group_id=150959
[2] http://www.geekologue.com/md4j/tutorial-with-maven.html
[3] http://www.geekologue.com/md4j/source-repository.html
Cheers,
Manos
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: File Upload design doubt
Posted by Francisco Exposito Aguilera <fc...@hotmail.com>.
I don't want any specific feature. I just want to know what is better for
uploading files (struts fileupload or commons file upload, taking into
account the disadvantages of every one; and if it is possible with struts
file upload to pass more attributes than the file from the form to the
action.
>From: "Martin Gainty" <mg...@hotmail.com>
>Reply-To: "Martin Gainty" <mg...@hotmail.com>
>To: "Struts Users Mailing List" <us...@struts.apache.org>
>Subject: Re: File Upload design doubt
>Date: Sun, 18 Feb 2007 18:59:25 -0500
>
>The Struts Fileuload will Autoload your Form Bean Data
>Is there a specific feature you are seeking?
>Anyone else?
>M-
>---------------------------------------------------------------------------
>This e-mail message (including attachments, if any) is intended for the use
>of the individual or entity to which it is addressed and may contain
>information that is privileged, proprietary , confidential and exempt from
>disclosure. If you are not the intended recipient, you are notified that
>any dissemination, distribution or copying of this communication is
>strictly prohibited.
>---------------------------------------------------------------------------
>Le présent message électronique (y compris les pièces qui y sont annexées,
>le cas échéant) s'adresse au destinataire indiqué et peut contenir des
>renseignements de caractère privé ou confidentiel. Si vous n'êtes pas le
>destinataire de ce document, nous vous signalons qu'il est strictement
>interdit de le diffuser, de le distribuer ou de le reproduire.
>----- Original Message -----
>From: "Francisco Exposito Aguilera" <fc...@hotmail.com>
>To: <us...@struts.apache.org>
>Sent: Sunday, February 18, 2007 3:36 PM
>Subject: Re: File Upload design doubt
>
>
> > Yes, I have commons-fileupload-1.1.1.jar and its dependent jar file
> > commons-io-1.3.1.jar.
> >
> > In fact, I´ve uploaded files from the two ways I explained in my first
>mail,
> > but I don´t know which one is better (Struts upload file or commons
>upload
> > file) due to the disadvantages I´ve found for every one and that I´ve
>put
> > forward.
> >
> >>From: "Martin Gainty" <mg...@hotmail.com>
> >>Reply-To: "Martin Gainty" <mg...@hotmail.com>
> >>To: "Struts Users Mailing List" <us...@struts.apache.org>
> >>Subject: Re: File Upload design doubt
> >>Date: Sun, 18 Feb 2007 15:24:43 -0500
> >>
> >>Francisco
> >>with regards to commons-file upload did you upload the latest
> >>fileupload.jar into your webapp/AppName/WEB-INF/lib ?
> >>http://jakarta.apache.org/site/downloads/downloads_commons-fileupload.cgi
> >>M-
> >>---------------------------------------------------------------------------
> >>This e-mail message (including attachments, if any) is intended for the
>use
> >>of the individual or entity to which it is addressed and may contain
> >>information that is privileged, proprietary , confidential and exempt
>from
> >>disclosure. If you are not the intended recipient, you are notified that
> >>any dissemination, distribution or copying of this communication is
> >>strictly prohibited.
> >>---------------------------------------------------------------------------
> >>Le présent message électronique (y compris les pièces qui y sont
>annexées,
> >>le cas échéant) s'adresse au destinataire indiqué et peut contenir des
> >>renseignements de caractère privé ou confidentiel. Si vous n'êtes pas le
> >>destinataire de ce document, nous vous signalons qu'il est strictement
> >>interdit de le diffuser, de le distribuer ou de le reproduire.
> >>----- Original Message -----
> >>From: "Francisco Exposito Aguilera" <fc...@hotmail.com>
> >>To: <us...@struts.apache.org>
> >>Sent: Sunday, February 18, 2007 2:20 PM
> >>Subject: File Upload design doubt
> >>
> >>
> >> > Hello all,
> >> >
> >> > I am trying to upload files, but I have some doubts.
> >> >
> >> > As I´ve read, there are two typical ways to do that:
> >> >
> >> > 1.Using StrutsFileUpload
> >> >
> >> > MyActionForm myForm = (MyActionForm)form;
> >> > FormFile myFile = myForm.getMyFile();
> >> > String fileName = myFile.getFileName();
> >> > String filePath = "G:/FILES/";
> >> >
> >> > File fileToCreate = new File(filePath, fileName);
> >> > InputStream stream = myFile.getInputStream();
> >> > BufferedInputStream in = new BufferedInputStream(stream);
> >> > BufferedOutputStream out = new
>BufferedOutputStream(new
> >> > FileOutputStream(fileToCreate));
> >> >
> >> > byte[] bytes = new byte[1048576];
> >> > int len = 0;
> >> >
> >> > while ( (len = in.read( bytes )) > 0 )
> >> > {
> >> > out.write( bytes, 0, len );
> >> > }
> >> >
> >> > out.close();
> >> > in.close();
> >> > stream.close();
> >> > myFile.destroy();
> >> >
> >> > 2.Using Jakarta Commons FileUpload
> >> >
> >> > DiskFileItemFactory factory = new
>DiskFileItemFactory();
> >> > factory.setSizeThreshold(4096);
> >> > factory.setRepository(new File("G:/FICHEROS/TEMP"));
> >> > ServletFileUpload upload = new
>ServletFileUpload(factory);
> >> >
> >> > upload.setSizeMax(2000000000);
> >> > List fileItems = upload.parseRequest(request);
> >> > Iterator i = fileItems.iterator();
> >> > FileItem fi = (FileItem)i.next();
> >> > String path="G:/FILES/";
> >> > String fileName = fi.getName();
> >> >
> >> > int lastCharacter = fileName.lastIndexOf("\\");
> >> > String title =
> >> > fi.getName().substring(lastCharacter+1,fi.getName().length());
> >> > fi.write(new File(path, title));
> >> >
> >> >
> >> > Everyone has its disadvantages:
> >> >
> >> > 1) the struts file upload is slower than the commons file upload:
>until
> >>the
> >> > tmp file is completed, all is equitable. But the difference comes
>with
> >>lines
> >> >
> >> > fi.write(new File(path, title));
> >> >
> >> > and
> >> >
> >> > byte[] bytes = new byte[1048576];
> >> > int len = 0;
> >> > while ( (len = in.read( bytes )) > 0 )
> >> > {
> >> > out.write( bytes, 0, len );
> >> > }
> >> >
> >> > I´ve tried to upload a 200MB file and it takes 1'20" with commons and
> >>2'5"
> >> > with struts. Is there any option to make struts upload file faster?
> >> >
> >> > 2) The commons file upload cannot be used inside an action. It must
>be
> >>an
> >> > independent servlet.
> >> >
> >> >
> >> >
> >> > As well as saving a file in the server (not in the database), I want
>to
> >>save
> >> > some info in the database. That is info of the file and of the person
> >>who
> >> > save it.
> >> > Here is the decision, but I don´t know which is the better one:
> >> >
> >> > 1) Use Struts fileUpload: Create a form with all fields I need and
>the
> >>input
> >> > file field and an action.
> >> > 2) Use Commons fileUpload: Create a form with all fields, but the
>input
> >> > file. Save all the info in the database and open then the servlet
>with
> >>the
> >> > file field. Save the file and if something wrong happens, delete the
> >> > database info saved in the last page (if it is possible).
> >> > 3) Any idea???
> >> >
> >> >
> >> > Thanks a lot.
> >> > Best regards,
> >> > Paco
> >> >
> >> > _________________________________________________________________
> >> > Acepta el reto MSN Premium: Protección para tus hijos en internet.
> >> > Descárgalo y pruébalo 2 meses gratis.
> >> >
> >>http://join.msn.com?XAPID=1697&DI=1055&HL=Footer_mailsenviados_proteccioninfantil
> >> >
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> > For additional commands, e-mail: user-help@struts.apache.org
> >> >
> >> >
> >
> > _________________________________________________________________
> > Descarga gratis la Barra de Herramientas de MSN
> >
>http://www.msn.es/usuario/busqueda/barra?XAPID=2031&DI=1055&SU=http%3A//www.hotmail.com&HL=LINKTAG1OPENINGTEXT_MSNBH
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
_________________________________________________________________
Descarga gratis la Barra de Herramientas de MSN
http://www.msn.es/usuario/busqueda/barra?XAPID=2031&DI=1055&SU=http%3A//www.hotmail.com&HL=LINKTAG1OPENINGTEXT_MSNBH
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: File Upload design doubt
Posted by Martin Gainty <mg...@hotmail.com>.
The Struts Fileuload will Autoload your Form Bean Data
Is there a specific feature you are seeking?
Anyone else?
M-
---------------------------------------------------------------------------
This e-mail message (including attachments, if any) is intended for the use of the individual or entity to which it is addressed and may contain information that is privileged, proprietary , confidential and exempt from disclosure. If you are not the intended recipient, you are notified that any dissemination, distribution or copying of this communication is strictly prohibited.
---------------------------------------------------------------------------
Le présent message électronique (y compris les pièces qui y sont annexées, le cas échéant) s'adresse au destinataire indiqué et peut contenir des renseignements de caractère privé ou confidentiel. Si vous n'êtes pas le destinataire de ce document, nous vous signalons qu'il est strictement interdit de le diffuser, de le distribuer ou de le reproduire.
----- Original Message -----
From: "Francisco Exposito Aguilera" <fc...@hotmail.com>
To: <us...@struts.apache.org>
Sent: Sunday, February 18, 2007 3:36 PM
Subject: Re: File Upload design doubt
> Yes, I have commons-fileupload-1.1.1.jar and its dependent jar file
> commons-io-1.3.1.jar.
>
> In fact, I´ve uploaded files from the two ways I explained in my first mail,
> but I don´t know which one is better (Struts upload file or commons upload
> file) due to the disadvantages I´ve found for every one and that I´ve put
> forward.
>
>>From: "Martin Gainty" <mg...@hotmail.com>
>>Reply-To: "Martin Gainty" <mg...@hotmail.com>
>>To: "Struts Users Mailing List" <us...@struts.apache.org>
>>Subject: Re: File Upload design doubt
>>Date: Sun, 18 Feb 2007 15:24:43 -0500
>>
>>Francisco
>>with regards to commons-file upload did you upload the latest
>>fileupload.jar into your webapp/AppName/WEB-INF/lib ?
>>http://jakarta.apache.org/site/downloads/downloads_commons-fileupload.cgi
>>M-
>>---------------------------------------------------------------------------
>>This e-mail message (including attachments, if any) is intended for the use
>>of the individual or entity to which it is addressed and may contain
>>information that is privileged, proprietary , confidential and exempt from
>>disclosure. If you are not the intended recipient, you are notified that
>>any dissemination, distribution or copying of this communication is
>>strictly prohibited.
>>---------------------------------------------------------------------------
>>Le présent message électronique (y compris les pièces qui y sont annexées,
>>le cas échéant) s'adresse au destinataire indiqué et peut contenir des
>>renseignements de caractère privé ou confidentiel. Si vous n'êtes pas le
>>destinataire de ce document, nous vous signalons qu'il est strictement
>>interdit de le diffuser, de le distribuer ou de le reproduire.
>>----- Original Message -----
>>From: "Francisco Exposito Aguilera" <fc...@hotmail.com>
>>To: <us...@struts.apache.org>
>>Sent: Sunday, February 18, 2007 2:20 PM
>>Subject: File Upload design doubt
>>
>>
>> > Hello all,
>> >
>> > I am trying to upload files, but I have some doubts.
>> >
>> > As I´ve read, there are two typical ways to do that:
>> >
>> > 1.Using StrutsFileUpload
>> >
>> > MyActionForm myForm = (MyActionForm)form;
>> > FormFile myFile = myForm.getMyFile();
>> > String fileName = myFile.getFileName();
>> > String filePath = "G:/FILES/";
>> >
>> > File fileToCreate = new File(filePath, fileName);
>> > InputStream stream = myFile.getInputStream();
>> > BufferedInputStream in = new BufferedInputStream(stream);
>> > BufferedOutputStream out = new BufferedOutputStream(new
>> > FileOutputStream(fileToCreate));
>> >
>> > byte[] bytes = new byte[1048576];
>> > int len = 0;
>> >
>> > while ( (len = in.read( bytes )) > 0 )
>> > {
>> > out.write( bytes, 0, len );
>> > }
>> >
>> > out.close();
>> > in.close();
>> > stream.close();
>> > myFile.destroy();
>> >
>> > 2.Using Jakarta Commons FileUpload
>> >
>> > DiskFileItemFactory factory = new DiskFileItemFactory();
>> > factory.setSizeThreshold(4096);
>> > factory.setRepository(new File("G:/FICHEROS/TEMP"));
>> > ServletFileUpload upload = new ServletFileUpload(factory);
>> >
>> > upload.setSizeMax(2000000000);
>> > List fileItems = upload.parseRequest(request);
>> > Iterator i = fileItems.iterator();
>> > FileItem fi = (FileItem)i.next();
>> > String path="G:/FILES/";
>> > String fileName = fi.getName();
>> >
>> > int lastCharacter = fileName.lastIndexOf("\\");
>> > String title =
>> > fi.getName().substring(lastCharacter+1,fi.getName().length());
>> > fi.write(new File(path, title));
>> >
>> >
>> > Everyone has its disadvantages:
>> >
>> > 1) the struts file upload is slower than the commons file upload: until
>>the
>> > tmp file is completed, all is equitable. But the difference comes with
>>lines
>> >
>> > fi.write(new File(path, title));
>> >
>> > and
>> >
>> > byte[] bytes = new byte[1048576];
>> > int len = 0;
>> > while ( (len = in.read( bytes )) > 0 )
>> > {
>> > out.write( bytes, 0, len );
>> > }
>> >
>> > I´ve tried to upload a 200MB file and it takes 1'20" with commons and
>>2'5"
>> > with struts. Is there any option to make struts upload file faster?
>> >
>> > 2) The commons file upload cannot be used inside an action. It must be
>>an
>> > independent servlet.
>> >
>> >
>> >
>> > As well as saving a file in the server (not in the database), I want to
>>save
>> > some info in the database. That is info of the file and of the person
>>who
>> > save it.
>> > Here is the decision, but I don´t know which is the better one:
>> >
>> > 1) Use Struts fileUpload: Create a form with all fields I need and the
>>input
>> > file field and an action.
>> > 2) Use Commons fileUpload: Create a form with all fields, but the input
>> > file. Save all the info in the database and open then the servlet with
>>the
>> > file field. Save the file and if something wrong happens, delete the
>> > database info saved in the last page (if it is possible).
>> > 3) Any idea???
>> >
>> >
>> > Thanks a lot.
>> > Best regards,
>> > Paco
>> >
>> > _________________________________________________________________
>> > Acepta el reto MSN Premium: Protección para tus hijos en internet.
>> > Descárgalo y pruébalo 2 meses gratis.
>> >
>>http://join.msn.com?XAPID=1697&DI=1055&HL=Footer_mailsenviados_proteccioninfantil
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> > For additional commands, e-mail: user-help@struts.apache.org
>> >
>> >
>
> _________________________________________________________________
> Descarga gratis la Barra de Herramientas de MSN
> http://www.msn.es/usuario/busqueda/barra?XAPID=2031&DI=1055&SU=http%3A//www.hotmail.com&HL=LINKTAG1OPENINGTEXT_MSNBH
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Re: File Upload design doubt
Posted by Francisco Exposito Aguilera <fc...@hotmail.com>.
Yes, I have commons-fileupload-1.1.1.jar and its dependent jar file
commons-io-1.3.1.jar.
In fact, I´ve uploaded files from the two ways I explained in my first mail,
but I don´t know which one is better (Struts upload file or commons upload
file) due to the disadvantages I´ve found for every one and that I´ve put
forward.
>From: "Martin Gainty" <mg...@hotmail.com>
>Reply-To: "Martin Gainty" <mg...@hotmail.com>
>To: "Struts Users Mailing List" <us...@struts.apache.org>
>Subject: Re: File Upload design doubt
>Date: Sun, 18 Feb 2007 15:24:43 -0500
>
>Francisco
>with regards to commons-file upload did you upload the latest
>fileupload.jar into your webapp/AppName/WEB-INF/lib ?
>http://jakarta.apache.org/site/downloads/downloads_commons-fileupload.cgi
>M-
>---------------------------------------------------------------------------
>This e-mail message (including attachments, if any) is intended for the use
>of the individual or entity to which it is addressed and may contain
>information that is privileged, proprietary , confidential and exempt from
>disclosure. If you are not the intended recipient, you are notified that
>any dissemination, distribution or copying of this communication is
>strictly prohibited.
>---------------------------------------------------------------------------
>Le présent message électronique (y compris les pièces qui y sont annexées,
>le cas échéant) s'adresse au destinataire indiqué et peut contenir des
>renseignements de caractère privé ou confidentiel. Si vous n'êtes pas le
>destinataire de ce document, nous vous signalons qu'il est strictement
>interdit de le diffuser, de le distribuer ou de le reproduire.
>----- Original Message -----
>From: "Francisco Exposito Aguilera" <fc...@hotmail.com>
>To: <us...@struts.apache.org>
>Sent: Sunday, February 18, 2007 2:20 PM
>Subject: File Upload design doubt
>
>
> > Hello all,
> >
> > I am trying to upload files, but I have some doubts.
> >
> > As I´ve read, there are two typical ways to do that:
> >
> > 1.Using StrutsFileUpload
> >
> > MyActionForm myForm = (MyActionForm)form;
> > FormFile myFile = myForm.getMyFile();
> > String fileName = myFile.getFileName();
> > String filePath = "G:/FILES/";
> >
> > File fileToCreate = new File(filePath, fileName);
> > InputStream stream = myFile.getInputStream();
> > BufferedInputStream in = new BufferedInputStream(stream);
> > BufferedOutputStream out = new BufferedOutputStream(new
> > FileOutputStream(fileToCreate));
> >
> > byte[] bytes = new byte[1048576];
> > int len = 0;
> >
> > while ( (len = in.read( bytes )) > 0 )
> > {
> > out.write( bytes, 0, len );
> > }
> >
> > out.close();
> > in.close();
> > stream.close();
> > myFile.destroy();
> >
> > 2.Using Jakarta Commons FileUpload
> >
> > DiskFileItemFactory factory = new DiskFileItemFactory();
> > factory.setSizeThreshold(4096);
> > factory.setRepository(new File("G:/FICHEROS/TEMP"));
> > ServletFileUpload upload = new ServletFileUpload(factory);
> >
> > upload.setSizeMax(2000000000);
> > List fileItems = upload.parseRequest(request);
> > Iterator i = fileItems.iterator();
> > FileItem fi = (FileItem)i.next();
> > String path="G:/FILES/";
> > String fileName = fi.getName();
> >
> > int lastCharacter = fileName.lastIndexOf("\\");
> > String title =
> > fi.getName().substring(lastCharacter+1,fi.getName().length());
> > fi.write(new File(path, title));
> >
> >
> > Everyone has its disadvantages:
> >
> > 1) the struts file upload is slower than the commons file upload: until
>the
> > tmp file is completed, all is equitable. But the difference comes with
>lines
> >
> > fi.write(new File(path, title));
> >
> > and
> >
> > byte[] bytes = new byte[1048576];
> > int len = 0;
> > while ( (len = in.read( bytes )) > 0 )
> > {
> > out.write( bytes, 0, len );
> > }
> >
> > I´ve tried to upload a 200MB file and it takes 1'20" with commons and
>2'5"
> > with struts. Is there any option to make struts upload file faster?
> >
> > 2) The commons file upload cannot be used inside an action. It must be
>an
> > independent servlet.
> >
> >
> >
> > As well as saving a file in the server (not in the database), I want to
>save
> > some info in the database. That is info of the file and of the person
>who
> > save it.
> > Here is the decision, but I don´t know which is the better one:
> >
> > 1) Use Struts fileUpload: Create a form with all fields I need and the
>input
> > file field and an action.
> > 2) Use Commons fileUpload: Create a form with all fields, but the input
> > file. Save all the info in the database and open then the servlet with
>the
> > file field. Save the file and if something wrong happens, delete the
> > database info saved in the last page (if it is possible).
> > 3) Any idea???
> >
> >
> > Thanks a lot.
> > Best regards,
> > Paco
> >
> > _________________________________________________________________
> > Acepta el reto MSN Premium: Protección para tus hijos en internet.
> > Descárgalo y pruébalo 2 meses gratis.
> >
>http://join.msn.com?XAPID=1697&DI=1055&HL=Footer_mailsenviados_proteccioninfantil
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
_________________________________________________________________
Descarga gratis la Barra de Herramientas de MSN
http://www.msn.es/usuario/busqueda/barra?XAPID=2031&DI=1055&SU=http%3A//www.hotmail.com&HL=LINKTAG1OPENINGTEXT_MSNBH
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: File Upload design doubt
Posted by Martin Gainty <mg...@hotmail.com>.
Francisco
with regards to commons-file upload did you upload the latest fileupload.jar into your webapp/AppName/WEB-INF/lib ?
http://jakarta.apache.org/site/downloads/downloads_commons-fileupload.cgi
M-
---------------------------------------------------------------------------
This e-mail message (including attachments, if any) is intended for the use of the individual or entity to which it is addressed and may contain information that is privileged, proprietary , confidential and exempt from disclosure. If you are not the intended recipient, you are notified that any dissemination, distribution or copying of this communication is strictly prohibited.
---------------------------------------------------------------------------
Le présent message électronique (y compris les pièces qui y sont annexées, le cas échéant) s'adresse au destinataire indiqué et peut contenir des renseignements de caractère privé ou confidentiel. Si vous n'êtes pas le destinataire de ce document, nous vous signalons qu'il est strictement interdit de le diffuser, de le distribuer ou de le reproduire.
----- Original Message -----
From: "Francisco Exposito Aguilera" <fc...@hotmail.com>
To: <us...@struts.apache.org>
Sent: Sunday, February 18, 2007 2:20 PM
Subject: File Upload design doubt
> Hello all,
>
> I am trying to upload files, but I have some doubts.
>
> As I´ve read, there are two typical ways to do that:
>
> 1.Using StrutsFileUpload
>
> MyActionForm myForm = (MyActionForm)form;
> FormFile myFile = myForm.getMyFile();
> String fileName = myFile.getFileName();
> String filePath = "G:/FILES/";
>
> File fileToCreate = new File(filePath, fileName);
> InputStream stream = myFile.getInputStream();
> BufferedInputStream in = new BufferedInputStream(stream);
> BufferedOutputStream out = new BufferedOutputStream(new
> FileOutputStream(fileToCreate));
>
> byte[] bytes = new byte[1048576];
> int len = 0;
>
> while ( (len = in.read( bytes )) > 0 )
> {
> out.write( bytes, 0, len );
> }
>
> out.close();
> in.close();
> stream.close();
> myFile.destroy();
>
> 2.Using Jakarta Commons FileUpload
>
> DiskFileItemFactory factory = new DiskFileItemFactory();
> factory.setSizeThreshold(4096);
> factory.setRepository(new File("G:/FICHEROS/TEMP"));
> ServletFileUpload upload = new ServletFileUpload(factory);
>
> upload.setSizeMax(2000000000);
> List fileItems = upload.parseRequest(request);
> Iterator i = fileItems.iterator();
> FileItem fi = (FileItem)i.next();
> String path="G:/FILES/";
> String fileName = fi.getName();
>
> int lastCharacter = fileName.lastIndexOf("\\");
> String title =
> fi.getName().substring(lastCharacter+1,fi.getName().length());
> fi.write(new File(path, title));
>
>
> Everyone has its disadvantages:
>
> 1) the struts file upload is slower than the commons file upload: until the
> tmp file is completed, all is equitable. But the difference comes with lines
>
> fi.write(new File(path, title));
>
> and
>
> byte[] bytes = new byte[1048576];
> int len = 0;
> while ( (len = in.read( bytes )) > 0 )
> {
> out.write( bytes, 0, len );
> }
>
> I´ve tried to upload a 200MB file and it takes 1'20" with commons and 2'5"
> with struts. Is there any option to make struts upload file faster?
>
> 2) The commons file upload cannot be used inside an action. It must be an
> independent servlet.
>
>
>
> As well as saving a file in the server (not in the database), I want to save
> some info in the database. That is info of the file and of the person who
> save it.
> Here is the decision, but I don´t know which is the better one:
>
> 1) Use Struts fileUpload: Create a form with all fields I need and the input
> file field and an action.
> 2) Use Commons fileUpload: Create a form with all fields, but the input
> file. Save all the info in the database and open then the servlet with the
> file field. Save the file and if something wrong happens, delete the
> database info saved in the last page (if it is possible).
> 3) Any idea???
>
>
> Thanks a lot.
> Best regards,
> Paco
>
> _________________________________________________________________
> Acepta el reto MSN Premium: Protección para tus hijos en internet.
> Descárgalo y pruébalo 2 meses gratis.
> http://join.msn.com?XAPID=1697&DI=1055&HL=Footer_mailsenviados_proteccioninfantil
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
File Upload design doubt
Posted by Francisco Exposito Aguilera <fc...@hotmail.com>.
Hello all,
I am trying to upload files, but I have some doubts
As I´ve read, there are two typical ways to do that:
1.Using StrutsFileUpload
MyActionForm myForm = (MyActionForm)form;
FormFile myFile = myForm.getMyFile();
String fileName = myFile.getFileName();
String filePath = "G:/FILES/";
File fileToCreate = new File(filePath, fileName);
InputStream stream = myFile.getInputStream();
BufferedInputStream in = new BufferedInputStream(stream);
BufferedOutputStream out = new BufferedOutputStream(new
FileOutputStream(fileToCreate));
byte[] bytes = new byte[1048576];
int len = 0;
while ( (len = in.read( bytes )) > 0 )
{
out.write( bytes, 0, len );
}
out.close();
in.close();
stream.close();
myFile.destroy();
2.Using Jakarta Commons FileUpload
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(4096);
factory.setRepository(new File("G:/FICHEROS/TEMP"));
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(2000000000);
List fileItems = upload.parseRequest(request);
Iterator i = fileItems.iterator();
FileItem fi = (FileItem)i.next();
String path="G:/FILES/";
String fileName = fi.getName();
int lastCharacter = fileName.lastIndexOf("\\");
String title =
fi.getName().substring(lastCharacter+1,fi.getName().length());
fi.write(new File(path, title));
Everyone has its disadvantages:
1) the struts file upload is slower than the commons file upload: until the
tmp file is completed, all is equitable. But the difference comes with lines
fi.write(new File(path, title));
and
byte[] bytes = new byte[1048576];
int len = 0;
while ( (len = in.read( bytes )) > 0 )
{
out.write( bytes, 0, len );
}
I´ve tried to upload a 200MB file and it takes 120 with commons and 25
with struts. Is there any option to make struts upload file faster?
2) The commons file upload cannot be used inside an action. It must be an
independent servlet.
As well as saving a file in the server (not in the database), I want to save
some info in the database. That is info of the file and of the person who
save it.
Here is the decision, but I don´t know which is the better one:
1) Use Struts fileUpload: Create a form with all fields I need and the input
file field and an action.
2) Use Commons fileUpload: Create a form with all fields, but the input
file. Save all the info in the database and open then the servlet with the
file field. Save the file and if something wrong happens, delete the
database info saved in the last page (if it is possible).
3) Any idea???
Thanks a lot.
Best regards,
Paco
_________________________________________________________________
Acepta el reto MSN Premium: Protección para tus hijos en internet.
Descárgalo y pruébalo 2 meses gratis.
http://join.msn.com?XAPID=1697&DI=1055&HL=Footer_mailsenviados_proteccioninfantil
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org