If you put it winthin the same directory than the servlet, you can access it
the following way :
public class myServlet extends HttpServlet {
boolean debug = true;
/** Variable hoplding properties objecf */
Properties properties = null;
/**
* Trying to access properties file
*/
public void init( ServletConfig config ) throws ServletException {
super.init(config);
String propertiesFile =
config.getInitParameter("properties");
if ( propertiesFile == null ) {
//> File name not defined within the web.xml
configuration file...
propertiesFile = new String(
this.getClass().getName() );
propertiesFile += ".properties";
}
if ( debug ) System.out.println( "Properties file : " +
propertiesFile );
try {
InputStream inputStream =
myServlet.class.getResourceAsStream( propertiesFile );
properties = new Properties();
properties.load( inputStream );
inputStream.close();
} catch ( IOException ioe ) {
this.getServletContext().log( "Unable to read
property file", ioe );
throw new ServletException( ioe.getMessage() );
}
}
} // End class
Hope that will help ! =;-)
Pascal-Eric Servais ( http://pages.infinit.net/denethor )
Cognicase ( division Web )
---
PGP Fingerprint : 8D0C FB66 CAF0 B9B3 E925 8D2E 7BDB 1D47 DC0B 4AEA
"Engagez-vous qu'ils disaient, vous allez voir du pays...", Anonyme
#> -----Original Message-----
#> From: Piotr Lipski [mailto:[EMAIL PROTECTED]]
#> Sent: Tuesday, December 05, 2000 9:11 AM
#> To: [EMAIL PROTECTED]
#> Subject: Re: properties
#>
#>
#> Hi,
#>
#> I think You can use
#> ResourceBundle.getBundle(YourPackageName.YourClassName)
#> to get access to properies file (it should be named
#> YourClassName.properties).
#>
#>
#> Piotr Lipski
#>
#> ----- Original Message -----
#> From: "William Brogden" <[EMAIL PROTECTED]>
#> To: <[EMAIL PROTECTED]>
#> Sent: Tuesday, December 05, 2000 3:00 PM
#> Subject: Re: properties
#>
#>
#> :
#> :
#> : andreas ebbert wrote:
#> : >
#> : > Hi there,
#> : > does anybody know where
#> : > to put property-files for servlets
#> : > so that tomcat finds them?
#> : > I tried to place them in the
#> : > same location as the .class-
#> : > -file but that didn´t work, any
#> : > idea´s?
#> : >
#> : > regards,
#> : > andreas
#> :
#> : If you are going to open a file, you have to use a
#> : fully qualified path. Use web.xml to pass an initialization
#> : parameter to the servlet giving the absolute path to
#> : the properties file. Here is an example:
#> :
#> : <servlet>
#> : <servlet-name>saynumb.au</servlet-name>
#> :
#> : <servlet-class>com.JSPbook.Chap04.NumberSoundServ</servlet-class>
#> : <init-param>
#> : <param-name>basepath</param-name>
#> :
#> :
#> <param-value>c:\\tomcat\\webapps\\Root\\JSPbook\\Chap04\\soun
#> ds</param-value
#> >
#> : </init-param>
#> : </servlet>
#> :
#> :
#> : --
#> : WBB - [EMAIL PROTECTED]
#> : Author of Java Developer's Guide to Servlets and JSP
#> : ISBN 0-7821-2809-2
#>