Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where does tomcat store my files?

I've created a web application using Netbeans. Before, when I was running the web app via netbeans and tomcat server (which was a zip), all my external files (uploaded files and other helper files I use for my app) are stored in bin directory.

Now, I tried installing an apache tomcat service using windows installer because I wanted to know how to deploy the project on a dedicated server. I have successfully deployed the war file using tomcat's deploy utility. However, when I run the project via the apache tomcat windows service, it is not saving the files in bin dir and it cannot read my files that I pasted in bin dir, too.

Where do you think should I place my files?

EDIT: Upon observing the tomcat service directory, I found out that it is store in the root. If I have my tomcat installed at 'E:\Apache\services\tomcat\', it is stored at the 'tomcat' directory.

like image 827
braindead Avatar asked Mar 04 '12 03:03

braindead


2 Answers

Ultimately, it is what your application does that determines where the files are stored.

By the sounds of it, your application is storing files in the current directory of the JVM, which happens to be the "bin" directory when you launch the web server via NetBeans. If so, you will find them, in whatever the current directory is when Tomcat is launched as a windows service.

Frankly, I think you've got this wrong. You should be making a conscious decision as to were uploaded files should be stored, and then making sure that the upload mechanism you are using puts them there.

Obviously, putting them in the current directory is a bad idea. You don't want them being stored in different places depending on how the web container is started. And obviously the "bin" directory is an inappropriate place. (What happens if the user tries to upload a file whose name matches one of the scripts that live in "bin"?)


So where should you be putting the files?

In my opinion, you've got three choices:

  • In a subdirectory of the work directory ... which is where Tomcat conventionally puts transitory files such as compiled JSPs.

  • In a custom subdirectory of the Tomcat installation directory.

  • In a separate directory somewhere else in the file system.

You shouldn't be dropping then in the webapp directory, because files there are typically blown away when the webapp is redeployed, and because there's a greater risk that uploaded files will interfere with your webapp.

You shouldn't be dropping them in the bin or logs or lib or config directories because of the risk of interference ... and because they are simply not the logical place.


If you want to write files relative to the root of the tomcat installation directory, you can find out what that is by calling System.getProperty("catalina.base").

But what ever you do, you need to make sure that a user can't accidentally or deliberately upload files to the wrong place; e.g by supplying an absolute pathname, or a pathname that uses "../../...." to escape from your upload area.

like image 150
Stephen C Avatar answered Oct 02 '22 08:10

Stephen C


When you install Apache, the project should be inside the webapp folder :

C:\Apache\tomcat\webapps

Like my Project is gaganisonline so the directory structure is something like this :

Path : C:\Apache\tomcat\webapps\gaganisonline

                            gaganisonline
                            |           |
                         WEB-INF      index.html
                            |
              ---------------------------
              |         |      |        |
            web.xml    src    lib    classes
like image 26
nIcE cOw Avatar answered Oct 02 '22 08:10

nIcE cOw