Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about the Current directory in my servlet

 
tuntony wei
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, guys
I am using eclipse and Tomcat to develope a simple Web tool. I have a question on the "new java.io.File( "." ).getCanonicalPath()" in my servlet/jsp. When I run the web project in my eclipse, I found the new java.io.File( "." ).getCanonicalPath() is D:\eclipse, But after I export the web project and put it into my CATALINA_HOME\webapp, the java.io.File( "." ).getCanonicalPath() is changed to CATALINA_HOME\bin

Here is what I am doing. In my servlet, I create a thread to carry a long time job. The thread is trying to read/write a batch of files, (these files includes some input files, some xml etc), do some db operations and put the result data into some files. These files have to be put at the current directory.

I found this current directory is the CATALINA_HOME\bin after I deployed my project in the CATALINA_HOME\webapp. I hope I could have a central place to put this batch of files and my result.

Could anybody give me a help and tell me how I can customize this dirrectory?

Thank you very much
 
Radhakrishna Sharma Gorenta
Ranch Hand
Posts: 63
Google App Engine Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You said very clearly, ok.but is your application running properly?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no concept of a "current directory" in web applications.

I'd supply the location of a temp folder, outside of the web app, via a property or context param.
 
tuntony wei
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rk sharma wrote:You said very clearly, ok.but is your application running properly?


Yes, the application is runing properly. I can get the result I want. But I just do not like the way of puting my files under the CATALINA_HOME\bin, I hope I could put them somewhere else
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then read my reply.
 
tuntony wei
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:There is no concept of a "current directory" in web applications.

I'd supply the location of a temp folder, outside of the web app, via a property or context param.


I call it current directory because of the "new java.io.File( "." ).getCanonicalPath()", sorry if the name is not good. Could you please suggest me where/how to configure it? For the context param, do you mean the parameters of Tomcat? I tried to make some configuration changes for tomcat, but I did not find anything good. Could you please tell me a little more?

Thank you very much
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tuntony wei wrote:Could you please suggest me where/how to configure it?

You can't. Period. As I said, it is not even a concept in web apps, so stop even thinking about it.

For the context param, do you mean the parameters of Tomcat?

Context parameters are set in the deployment descriptor. They have nothing to do with Tomcat.

It'd be best to have a properties file in which you can set such values that you do not want to hard-code into the code.
 
tuntony wei
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
tuntony wei wrote:Could you please suggest me where/how to configure it?

You can't. Period. As I said, it is not even a concept in web apps, so stop even thinking about it.

For the context param, do you mean the parameters of Tomcat?

Context parameters are set in the deployment descriptor. They have nothing to do with Tomcat.

It'd be best to have a properties file in which you can set such values that you do not want to hard-code into the code.


OK, thank you. I will try
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic