I'm putting together a website with JSP pages and servlets. I have built a admin control page for some site management. I would like the ability to add a directory like "http:\\localhost\directory\path\files" by typing the path "\directory\path\files" into a text field on a jsp page, store path in MySQL db for use in creating links. I want the path to append to the end of http:\\localhost\. Is this possible using a relitive path as opposed to absolute path. It seems that when I create the new directory File f1 = new File() in my servlet it is relative to my WEB-INF folder, I want it to be reative to my ROOT directory.
will return a file object to the location of the top of your web application on the file system, for example, "c:\program files\apache tomcat 6\webapps\myapp"
From the file object, you can get work to parse out or extract the prefix or pieces of it, and do a relative path from it.?
Error: Keyboard not attached. Press F1 to continue.
Joined: Jan 02, 2009
Thanks Travis, That did give me what I'm looking for but I have another problem.
Can I create folders in this manner in the Tomcat ROOT Directory. My folders fail to create in the ROOT dir when obtianing the path from the solution provided. I am able to create folders one level up in the webapps directory. Are there settings I need to configure without leaveing web server unsecure.
Is it best to keep my .jsp's under the ROOT directory?
Here are snipets of code I'm using to create the directories.
From .jsp I get the ROOT path then append the folder\ folders I want to create by passing a form value.
From servlet I call doCreateDir(relativeDir);
Here is code to create path. Returned is Failure to create directory.
Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.
You can go back and change your post to add code tags by clicking the button on your post.