File creation in the web applications' root

S

sasuke

Hello all.

Is it possible to get the path at which my application root is placed
by means of either the ServletContext or the ServletConfig object?

What I am trying to do here is to dynamically create a Javascript file
on the fly and put in the script directory of my web application. But
since the working directory in a web applications case is the
directory which contains the app servers' executable, any new file
created would be created there and I don't want to hard code the path
to my script folder. I want everything to be relative to the
applications' root as far as possible.

Can it be done without any special configuration, the way I can get a
resource present in the application root by the getResource() method?
Any kind of help would be greatly appreciated.

Regards,
sasuke.
 
Joined
Dec 11, 2007
Messages
1
Reaction score
0
try:
ServletContext sc = this.getServlet().getServletConfig().getServletContext();

File yourfile = new File(sc.getRealPath("/yourscriptdirectory/yourfile.js"));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top