• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

absolute url's

 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't use a URL to access the properties file.
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what application server are you using?
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using iPlanet as everything. I think it's got a built-in application server.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic