directory:
======================================================================
/WEB-INF/classes/database.xml
xml(database.xml):
======================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="username">name</entry>
<entry key="password">pass</entry>
<entry key="url">jdbc:mysql://192.168.0.105/hihi</entry>
</properties>
code:
======================================================================
Properties prop = new Properties();
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("database.xml");
try {
prop.loadFromXML(inputStream);
} catch (InvalidPropertiesFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String username = prop.getProperty("username");
note:
=====================================================================
1. file path is very critical
2. conventional FileInputStream input = new FileInputStream("XXXX");
seem not working in web application (I am not sure if this is the path problem or not)
3. to disply xml in html, change <> to & lt; & gt;
Also see:
http://jaitechwriteups.blogspot.com/2007/01/how-to-read-properties-file-in-web.html
Thursday, January 7, 2010
Wednesday, January 6, 2010
tomcat manager setting
To access manager page of tomcat, you should modify %tomcat_home%/conf/tomcat-users.xml
Add
Add
Subscribe to:
Posts (Atom)