Some custom configurations are always used on the website. I put them in a properties file, such as config. properties this file is placed with struts. in the same XML folder, here I am under SRC.
1. Create a new tool class propertiesutil, and define a public static java. util. properties Class Object PPs in it
2. Create a listener class webconfiglistener and implement the servletcontextlistener interface.
Public void contextinitialized (servletcontextevent arg0 ){
Propertiesutil. PPS = new properties ();
Try {
String Path = (getclass (). getclassloader (). getresource (""). touri (). getpath ();
Fileinputstream FCM = new fileinputstream (path + "config. properties ");
Propertiesutil. PPS. Load (FCM );
} Catch (exception e ){
E. printstacktrace ();
}
}
3. Add webconfiglistener in Web. xml
<Listener>
<Listener-class> com. phonesale. Common. webconfiglistener </listener-class>
</Listener>
4. InProgramUse: propertiesutil. PPS. getproperty (key );