• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

include properties file in jsp

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please help me use the properties of db.properties in connectDb.jsp.

i need to use db.user like properties , is its possible directly from a jsp without writing a bean ...

can include file help ?
 
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about something like:



Or instead of using a properties file you could just put all the properties as ServletConfig or ServletContext init parameters.

-Yuriy
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can use the following approach. write all your properties in properites file and store that file in /WEB-INF/classes .

my properties file contains
url=jdbc:mysql://venu/tms10?user=root&password=umarao
driver=com.mysql.jdbc.Driver

and in your code you can read these properties file. using the following code.

resourceBundle= ResourceBundle.getBundle("resource");
dBURL= gclsResourceBundle.getString("url");
dBDriver= gclsResourceBundle.getString("driver");

but this works if you are reading your values through standard java class.
and class is stored in /WEB-INF/classes. if you want it to be read from
JSP page you have to adjust your path in ResourceBundle. But it is not good
practice to connect to the database directly from jsp page.
[ March 31, 2005: Message edited by: Bonagiri UmaMaheshwar Rao ]
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can get the class loader which container uses to load servlet classes,then get your propertyfile as resource.

ClassLoader cl = this.getClass().getClassLoader();
InputStream is =cl.getResourceAsStream("package/db.properties");
Properties props = new Properties();
props.load(is);

String username = props.getProperty("username");

Again..loading property fil in jsp is not a good practice.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic