tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From José Moreira <jmore...@e-terno.net>
Subject RE: properties files
Date Tue, 25 Feb 2003 16:24:01 GMT
yep, that will work because due to my inexperience im having a lot trouble
working with files ...

ill go try web.xml

-----Mensagem original-----
De: Simone Chiaretta [mailto:simonech@logicapiu.it]
Enviada: terça-feira, 25 de Fevereiro de 2003 14:36
Para: Tomcat Users List
Assunto: R: properties files


I store properties in my the app WEB-INF/web.xml

	<context-param>
		<param-name>smtpServer</param-name>
		<param-value>my.smtpserver.net</param-value>
		<description>SMTP server to be used to send email from forms in the
website</description>
	</context-param>

and I access the value also in JSP pages with

String value =  getServletContext().getInitParameter("smtpServer");

and I assure u that it works even with JSP not only with servlet, but I
never tryed accessing it from inside a bean.

The only problem is that when you change the value you have to reload the
application..

hope that helps
Simo

> -----Messaggio originale-----
> Da: José Moreira [mailto:jmoreira@e-terno.net]
> Inviato: martedì 25 febbraio 2003 15.25
> A: Tomcat Users List; aheritier@sopragroup.com
> Oggetto: RE: properties files
>
>
> 	thank you for the attention, im developing a bean to
> interact with the
> properties file.
>
> 	I believe that  ServletContext is only available to servlets,
>
> but perhaps the filename can be a parameter in the constructor :D
>
> 	the reason why im using a properties file is to make the
> configuration
> transparent and easy, to my clients...
>
> so i they change the mysql db parameters they can easily edit the
> properties
> file without much knowledge.
>
> also another advantage i saw in that was the ability to load and save
> directly to a file.
>
> if there is a better way im all ears :)
>
>
> -----Mensagem original-----
> De: Arnaud HERITIER [mailto:aheritier@sopragroup.com]
> Enviada: terça-feira, 25 de Fevereiro de 2003 12:51
> Para: 'Tomcat Users List'
> Assunto: RE: properties files
>
>
> You need to put your property files in WEB-INF/classes or in a jar in
> WEB-INF/lib
>
> Then you can use the getResourceAsStream(..) method of the
> ServletContext of
> your webapp :
>
>
> properties.load(getServletContext().getResourceAsStream(filePath))
>
> Arnaud
>
>
> > -----Message d'origine-----
> > De : José Moreira [mailto:jmoreira@e-terno.net]
> > Envoyé : mardi 25 février 2003 13:36
> > À : Tomcat Users List
> > Objet : properties files
> >
> >
> > Hello, im using a propeties file to store and retrieve
> > application settings
> > (like db conection) using this code :
> >
> >     private Properties properties;
> >
> >     private String status;
> >
> >     private boolean NovoConfig;
> >
> >     /** Creates new ConfigReaderBean */
> >     public ConfigReaderBean() {
> >
> >         Properties properties = new  Properties();
> >
> >         NovoConfig = false;
> >
> >         try {
> >
> >             properties.load(new FileInputStream("config.properties"));
> >
> >         } catch (IOException e) {
> >
> >
> >             System.out.println("Erro ao ler config: "+e.getMessage());
> >
> >
> >
> > properties.setProperty("database.url","http://localhost/mysql");
> >
> >             NovoConfig = true;
> >
> >         }
> >
> >         if (NovoConfig) {
> >
> >             try {
> >
> >                 properties.store(new
> > FileOutputStream("newconfig.properties"),null);
> >
> >                 System.out.println("Criado: newconfig.properties");
> >
> >             } catch (IOException e) {
> >
> >                 System.out.println("Erro ao criar novo config:
> > "+e.getMessage());
> >
> >             }
> >
> >
> >         }
> >
> > the problem is that it doesnt load the file and saves the
> > 'newconfig.properties' file under the Netbeans IDE dir,
> >
> > how can i load the file located under my webapp WEB-INF dir ?
> >
> >
> >
> >
> >
> > ---------------<*>----------------------
> > José Moreira
> >
> > Técnico de Informática | IT Technician
> >
> > Vila Nova de Gaia, Portugal
> >
> > E-Mail: jmoreira@e-terno.net
> >
> > MSN: jose_guedes@hotmail.com
> >
> > ICQ: 136936120
> >
> > IRC: ethernal (irc.ptnet.org)
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message