aspose file tools*
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
JavaRanch » Java Forums » Java » JSP
Bookmark "include properties file in jsp" Watch "include properties file in jsp" New topic
Author

include properties file in jsp

Priya Singh
Ranch Hand

Joined: Mar 19, 2004
Posts: 33
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

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.

-Yuriy
Bonagiri UmaMaheshwar Rao
Greenhorn

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
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

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/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.


http://learnertobeginner.blogspot.com/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: include properties file in jsp