"Bommakanti, Vamsee" wrote:
>
> Thanks Hans
> I was able to create multiple environments. I have another question, i have
> properties file for my different contexts with different data some thing
> like database connection url etc.,
> When i try to load the property file in my bean, it gives me file not found
> exception.
> I tried placing the properties file in all the places under my webapps/myapp
> directories, but it doesnot seem to work.
> Could u help me in this matter.
> I read that i can add the path of the properties file into the class path,
> but this will not help me coz, the properties file has the same name for all
> the contexts but with different data, and i donot want to change my bean for
> loading different propeties files(may be i will if nothing else works
> out...)

Put the properties files somewhere under WEB-INF, e.g. in
WEB-INF/conf/myprops.properties, and use ServletContext.getResourceAsStream()
to read it:

  InputStream is = ctx.getResourceAsStream("/WEB-INF/conf/myprops.properties");

If you do this in a bean, you must first give the bean access to the
ServletContext object. The "application" variable contains a reference:

  <jsp:setProperty name="myBean" property="app" value="<%= application %>" />

A better approach, IMHO, is to use a custom action as an interface to
the bean. A custom action has access to the ServletContext, as well as
all other request and application data, automatically and is easier to
use in a page. For more about custom actions, read a good JSP book that
covers JSP 1.1, for instance the book I wrote:

  <http://TheJSPBook.com/>

Hans
--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com
Author of JavaServer Pages (O'Reilly), http://TheJSPBook.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to