Thanks for all the advices
... the getRealPath() is what I am looking for.

Cheers,
Wendy

Costin Manolache wrote:

> > Hi, I put my properties files under my web server (IBM Http Web server
> > powered by Apache)
> > htdocs directory, say
> >     htdocs\props
> >
> > Now, I have a servlets that need to read a properties file under this
> > directory.
> > How?  I transverse through the classpath inside my servlet, and the
> > htdocs directory
> > is not reachable.
> >
> > Specifically, I specificied "props\hello.properties" in one of the
> > initArg of my servlet.
> > and used class path returned in runtiem to find this file but with no
> > success.
>
> First, it is very dangerous to put properties file in htdocs - anyone can
> read, so don't put your passwords inside.
>
> You can use the full path to the prop file in your initArg.
>
> Or you can use ServletContext.getRealPath() ( pass
> "/props/hello.properties" as argument ) to get the full path.
>
> Or include htdocs in CLASSPATH and use ClassLoader.getResource().
> (Or put your properties in CLASSPATH, in the same place as your class
> files.)
>
> Or just use the normal servlet init args - if you can express your
> configuration in a properties, you can also use the servlets.properties.
> You may get a nice configuration tool for free ( the servlet engine
> admin tools).
>
> I always like to use the ClassLoader, you have to set CLASSPATH anyway, so
> why adding a new configuration? ( plus you can have a "default" properties
> in the same jar as your classes, you don't even need to unzip ).
> ( getResourceAsStream() is a very usefull method - it can read a file
> anywhere in your classpath, including jar files.)
>
> Regards,
> Costin
>
> > Hi, I put my properties files under my web server (IBM Http Web server
> > powered by Apache)
> > htdocs directory, say
> >     htdocs\props
> >
> > Now, I have a servlets that need to read a properties file under this
> > directory.
> > How?  I transverse through the classpath inside my servlet, and the
> > htdocs directory
> > is not reachable.
> >
> > Specifically, I specificied "props\hello.properties" in one of the
> > initArg of my servlet.
> > and used class path returned in runtiem to find this file but with no
> > success.
> >
> > Any help is appreciated.
> > Thanks,
> > Wendy
> >
> > ___________________________________________________________________________
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> > of the message "signoff SERVLET-INTEREST".
> >
> > Archives: http://archives.java.sun.com/archives/servlet-interest.html
> > Resources: http://java.sun.com/products/servlet/external-resources.html
> > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
> >
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to