File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes include properties file in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "include properties file in jsp" Watch "include properties file in jsp" New topic

include properties file in jsp

Priya Singh
Ranch Hand

Joined: Mar 19, 2004
Posts: 33
please help me use the properties of 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

Joined: Dec 13, 2004
Posts: 429
How about something like:

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

Bonagiri UmaMaheshwar Rao

Joined: Mar 27, 2005
Posts: 12
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

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

Joined: May 26, 2004
Posts: 94
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/");
Properties props = new Properties();

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

Again..loading property fil in jsp is not a good practice.
I agree. Here's the link:
subject: include properties file in jsp
It's not a secret anymore!