Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

include properties file in jsp

 
Priya Singh
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • 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 ?
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
  • 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
 
Bonagiri UmaMaheshwar Rao
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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 ]
 
Poobhathy Kannan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic