Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting Current Path  RSS feed

 
ninad parkhi
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Please see my probelm and help me , it's urgent.
I am having directory structure like
d:\projects\cencal\servlet
d:\projects\taxi\servlet
d:\projects\F_H\servlet
In all the servlet folder there is file Validate_User.class
Also all servlet contains user.propertis file from which I get parameters to connect to DATABASE.
I am using FileReader to read data from file and then connect to database.But in this case I am maintaining THREE different versions of Validate_User.class with FileReader as
FileReader fis =
new FileReader("d:\\projects\\cencal\\servlet\\user.properties");
FileReader fis =
new FileReader("d:\\projects\\cencal\\taxi\\user.properties");
FileReader fis =
new FileReader("d:\\projects\\cencal\\F_H\\user.properties");
I want to make it GENERIC like I should get the CURRENT PATH and then appened the user.properties to it.
So when d:\projects\cencal\servlet\Validate_User.class is invoked I should get path as d:\projects\cecal\servlet and then I will append user.propertis to it and read from file.
Is there is any way that I can do this?
Thanks,
Ninad
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The concept of current path is meaningless in a servlet engine environment. Why don't you use initialization parameters to set a base directory for the particular installation?
Bill
 
Joe Nguyen
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ninad
You may have different paths that relative to your web root. You can create three different subdirectory under our web root and put appropriate user.properties under those new directory. When you invoke the servlet, you can provide pathInfo along with your url. For instance, /servlet/com.myapp.MainServlet/newDirectory1?para=value. Within your servlet, you can call the getPathInfo()that returns ****/newDirectory1. Then you can append user.properties to the return value.
The other way you can treat each of your user.properties as an url. You can open the url and read the file.
Joey
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or you can use the code from this thread. It locates and loads a properties file that has been stored on the class path. There is also a small tweak so it still works in web apps (when you run into ClassLoader problems)
Dave.
 
ninad parkhi
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi William,
I am using oracle 9IAS (Apache/Jserv).
Can you please tell me where can I set initialization parameters
so that I can I can set a base directory for the particular installation?
Regards,
Ninad
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!