Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create file under tomcat root directory. 1

Status
Not open for further replies.

Keyth

Programmer
Feb 10, 2007
113
GB
Hello.

Is it possible for a Java Servlet to create a file on a tomcat web server? What I mean is, is there a way through code that I can get the path for my tomcat root directory and place the file on the same path? I can create the file using my own installation of Tomcat because I know the path to the ROOT folder but how can you get the path if your web app is hosted by a remote company?

I am trying to create an XML file when I update my stock listing so that other users can download this file for their own use.

Thanks.
 
Code:
        public static String WEBAPP_ROOT;

        /**
        *       Initialize the servlet and set up some static variables :<br>
        */
        public void init() {
                WEBAPP_ROOT = getServletContext().getRealPath("/");
        }

I would not recommend doing what you suggest though - you should use some other directory as your datastore.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Thats very helpful thank you.

I need to make the file available for a user to download. Would it be better to save the file to a folder under the root with security settings set?
 
I would save the file in some location that is not under Tomcat's directory, preferably on some backed up network storage.

You should control access to the file via your webapp.



--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
I wanted to use this method in order to make an XML file available for general public, it lists available stock items and there is no info provided within the file that is sensitive or might make my app vulnerable. I thought you were suggesting that I might create a risk by saving it to my root folder but I need to make the XML file available for download. My data is stored in MySQL and all servlets etc handle the retrieval/update of data.

Thanks very much for your help with my post :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top