| Author |
Question about the Current directory in my servlet
|
tuntony wei
Greenhorn
Joined: Jun 29, 2011
Posts: 13
|
|
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
|
 |
rk sharma
Ranch Hand
Joined: Jun 25, 2011
Posts: 50
|
|
|
You said very clearly, ok.but is your application running properly?
|
Regards,
RK
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56152
|
|
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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
tuntony wei
Greenhorn
Joined: Jun 29, 2011
Posts: 13
|
|
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
Joined: Jan 10, 2002
Posts: 56152
|
|
|
Then read my reply.
|
 |
tuntony wei
Greenhorn
Joined: Jun 29, 2011
Posts: 13
|
|
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
Joined: Jan 10, 2002
Posts: 56152
|
|
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
Joined: Jun 29, 2011
Posts: 13
|
|
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
|
 |
 |
|
|
subject: Question about the Current directory in my servlet
|
|
|