File I/O in Struts 1.2.x
Is it possible to upload a file to a server, process the data as it needs to be, and then write the file back to the local machine from which it originally was uploaded all in a single execute method of a single action class? Or, am I required to have an action for uploading it to the server, and another for processing, and another for downloading, or something in between? -- View this message in context: http://old.nabble.com/File-I-O-in-Struts-1.2.x-tp26779909p26779909.html Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: File I/O in Struts 1.2.x
I think that's possible. For example processing an excel file with POI, in your form you choose the file, then submit form and in the action you process the excel file with POI libraries, you edit the excel file with something like adding rows or something like that, then you write the stream of the excel file at the end of the method and returning null from your action method, then it will appear in the form the dialog box to download excel file. That's an example with an excel file, but i think that you can do the process with another file type. 2009/12/14 davargas123 davargas...@gmail.com Is it possible to upload a file to a server, process the data as it needs to be, and then write the file back to the local machine from which it originally was uploaded all in a single execute method of a single action class? Or, am I required to have an action for uploading it to the server, and another for processing, and another for downloading, or something in between? -- View this message in context: http://old.nabble.com/File-I-O-in-Struts-1.2.x-tp26779909p26779909.html Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org -- Oscar
Re: File I/O with Struts
Unless the file is at an already known, absolute location, you need some way to determine the correct path to it. If it's part of your WAR, and the WAR could have been deployed anywhere (according to where the container is installed, etc.) then you will need a way to figure out the correct path to load. You can place it anywhere you like within the WAR and access it using getRealPath(). However, if the container the webapp is running in doesn't expand WAR files, that might not work. Another alternative is to place the file in the classes and load it via getResource(). Or, install it to a known location (/etc, C:\Program Files\Your Application\, or whatever) so you can reference it with an absolute path. L. Asad Habib wrote: Hi Laurie. Actually, I am not using any method to determine the path of the file. Should I be doing that? In general, where should one place files used for I/O within the WAR structure? Thanks for your help. - Asad On Thu, 7 Sep 2006, Laurie Harper wrote: Asad Habib wrote: I am trying to read from a file using a utility class that I invoke from an action. However, my application is unable to find the file and a java.io.FileNotFoundException is thrown. I have tried placing the file in /WEB-INF/classes as well as the root directory of the application however the error is still thrown. Any help would be appreciated. Thank you. It's hard to help without seeing the code, but you are probably specifying an incorrect path to the file. Are you using getRealPath() [1] to figure out the real file location? L. [1] http://tomcat.apache.org/tomcat-5.0-doc/servletapi/javax/servlet/ServletContext.html#getRealPath(java.lang.String) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
File I/O with Struts
I am trying to read from a file using a utility class that I invoke from an action. However, my application is unable to find the file and a java.io.FileNotFoundException is thrown. I have tried placing the file in /WEB-INF/classes as well as the root directory of the application however the error is still thrown. Any help would be appreciated. Thank you. - Asad - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: File I/O with Struts
Asad Habib wrote: I am trying to read from a file using a utility class that I invoke from an action. However, my application is unable to find the file and a java.io.FileNotFoundException is thrown. I have tried placing the file in /WEB-INF/classes as well as the root directory of the application however the error is still thrown. Any help would be appreciated. Thank you. It's hard to help without seeing the code, but you are probably specifying an incorrect path to the file. Are you using getRealPath() [1] to figure out the real file location? L. [1] http://tomcat.apache.org/tomcat-5.0-doc/servletapi/javax/servlet/ServletContext.html#getRealPath(java.lang.String) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: File I/O with Struts
Hi Laurie. Actually, I am not using any method to determine the path of the file. Should I be doing that? In general, where should one place files used for I/O within the WAR structure? Thanks for your help. - Asad On Thu, 7 Sep 2006, Laurie Harper wrote: Asad Habib wrote: I am trying to read from a file using a utility class that I invoke from an action. However, my application is unable to find the file and a java.io.FileNotFoundException is thrown. I have tried placing the file in /WEB-INF/classes as well as the root directory of the application however the error is still thrown. Any help would be appreciated. Thank you. It's hard to help without seeing the code, but you are probably specifying an incorrect path to the file. Are you using getRealPath() [1] to figure out the real file location? L. [1] http://tomcat.apache.org/tomcat-5.0-doc/servletapi/javax/servlet/ServletContext.html#getRealPath(java.lang.String) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]