jQuery in Action, 2nd edition*
The moose likes JDBC and the fly likes absolute url's Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "absolute url Watch "absolute url New topic
Author

absolute url's

Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
Hi!
I think what I'm trying to do is an absolute url....I'm not sure!
In my application, I read variables on a properties file. Right now, the path to the file is hard-coded (ie e:\sites\.....)
I need to change that so that I can read the properties file no matter where my servlet is. I tried using the same format as when I call another servlet from an html page
(form action="http://keoki.ncr.pwgsc.gc.ca:8080/....")
but that doesn't seem to work.
What is the correct way to write the url?
Thanks!
Annette
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
You can't use a URL to access the properties file.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
Really?
So if the application gets moved to another server, we would have to move the properties file and then chance the path in every servlet that calls it?
(just need to get my case together so I can tell them it's not possible!!)
Dmitry Shekhter
Greenhorn

Joined: Feb 21, 2001
Posts: 26
what application server are you using?
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
I'm using iPlanet as everything. I think it's got a built-in application server.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Annette L'Heureux:
In my application, I read variables on a properties file. Right now, the path to the file is hard-coded (ie e:\sites\.....)

Eeeks! Hardcoded absolute paths!
There are a couple of ways you can get at resources. The most appropriate is probably ServletContext.getResourceAsStream(). This allows you to open an InputStream on a resource file. This is relative to the webapp-root, but does not go through the web server and can access privileged directories such as WEB-INF.
For example, if your web-app is in
   /my/directory/myapp/
then getResourceAsStream("/WEB-INF/myresource.file") will open
   /my/directory/myapp/WEB-INF/myresource.file
Alternatively there's the getResource() method giving back a URL rather than an InputStream. You can get the servlet context object using Servlet.getServletConfig().getServletContext().
If you would rather retrieve stuff from the CLASSPATH, you can use either getClass().getResourceAsStream() or ClassLoader.getSystemResourceAsStream(). But I don't think that is quite as portable or convenient.
HTH
- Peter

[This message has been edited by Peter den Haan (edited March 02, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: absolute url's