0

In my web based application (Tomcat7 / JDK 7 - JSP 3.0), I built a translator to take csv files, clean them up, and save the file off. A second part then parses the file for certain information and creates a second file (so it can be loaded into another system for verification). This happens every day. These files are being written to ${ECLIPSE_HOME} (because I'm running this in Eclipse).

What I want to do is have a folder created in the application's root directory {i.e, [app-root]/toBeDLd} specifically for saving the generated files into and downloading them, have my front end JSP be able to read and display the files (like a list of downloadable files, you click the link it downloads in your web browser) and at a specific time, delete all the files in that directory. I don't need to keep them, or have a backup of them.

From what I have read, Sending OutputStream to browser and let browser save it would be a decent starting point, but I have also read some other comments on SO that it is a violation of servlet spec to save files inside of the web app directory. I'm not sure if that is due to it being the root of the webapp or not though. Ideally I would like to keep this completely contained within the web application.

Is this possible? Is this the best way to do this?

Community
  • 1
  • 1
ResourceReaper
  • 555
  • 2
  • 10
  • 27

1 Answers1

0

Dont put it anywhere under Tomcats webapps. This is probably a very bad idea.

My Suggestion is to add a dataDir init parameter to you web.xml:

<servlet>
    <servlet-name>MyServlet</servlet-name>
    <servlet-class>com.example.MyServlet</servlet-class>
    <init-param>
        <param-name>dataDir</param-name>
        <param-value>/var/data</param-value>
    </init-param>
</servlet>

You can then use this parameter inside your servlet:

getServletConfig().getInitParameter("dataDir");

If you want it compact with your Tomcat maybe choose $CatalinaBase/dataDir

Whoever deploys the Servlet now can decide where to put the Data. Maybe an extra partition without execute rights. Maybe an extra fast partition.

Peter Lamby
  • 285
  • 2
  • 7
  • And I think that is what the OP was hinting at in the link above, but it's not 100% clear. I agree that putting ANYTHING except webapps in the ${WEBAPPS_HOME} directory is a very bad idea. – ResourceReaper Apr 10 '14 at 15:23