2/26/02 8:39:01 PM, Ursula Pieper <[EMAIL PROTECTED]> wrote:
>
>Hi,
>
>my servlets need to access a properties file
>(/var/tomcat4/webapps/application/WEB-INF/classes/pro.properties).
>
>I tried to get the parameter to read properly by adding parameter entries
>at different location. so now:
>
>My server.xml entry looks like this:
>
><Context path="/application" docBase="application" debug="9"
>reloadable="true">
><Parameter name="CONFIG_FILE"
>value="/var/tomcat4/webapps/application/WEB-INF/classes/pro.properties"
>override="false"/>
><param-name>CONFIG_FILE</param-name>
><param-value>/var/tomcat4/webapps/application/WEB-INF/classes/pro.properties
></param-value>
></Context>
>
>and the web.xml:
>
><display-name>/application</display-name>
><description>application</description>
>
><context-param>
><param-name>CONFIG_FILE</param-name>
><param-value>/var/tomcat4/webapps/application/WEB-INF/classes/pro.properties
></param-value>
></context-param>
>
>This entry gets recognized at tomcat startup:
>in catalina.out:
>XmlMapper: org.apache.catalina.core.StandardContext.addParameter( CONFIG_FILE,
>/var/tomcat4/webapps/application/WEB-INF/classes/pro.properties)
>
>The call for is in the servlet looks like this:
>
>init(ServletConfig config)
>throws ServletException
> {
> super.init(config);
> try
> {
> configPrefs = new Properties();
> servletContext = config.getServletContext();
> if ( config.getInitParameter("CONFIG_FILE") == null )
> throw new ServletException( "No CONFIG_FILE param" );
> ...
>
>
>and I am getting the following error message:
>javax.servlet.ServletException: No CONFIG_FILE param
>
>Can anybody help me straighten this out?
>
>I am new to this and want to get this application to run. I am just now
>learning java and tomcat, so please excuse my probably trivial question.
>
>I am running
>Tomcat 4.0.1
>jdk1.3.1
>on redhat 7.2
>
>Thanks a lot!
>
Instead of accessing the fileSystem, try the following instead:
InputStream inputStream =
getServletContext().getResourceAsStream("/WEB-INF/classes/pro.properties");
Properties properties = new Properties();
properties.load(inputStream);
inputStream.close();
This will let you later bundle the whole application as a war file (similar to zip or
tar files, and created with the jar command).
Also, you won't have to change the CONFIG_FILE parameter when you move your web
application to some other folder.
>Ursula
>
Sriram
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
To unsubscribe: <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>