One of the most common tags in struts is this:
<bean:message key= "Welcome.title"/>
As we all know, this label does things like this:
Access to resource files defined in Struts-config.xml, typically application.properties, is generally defined as:
<message-resources parameter= "Resources.application"/>
Based on the above definition, struts will go to web-inf/classes/resource/ Go down and find Application.properties file, this is from the above configuration information on the surface looks like this, but by looking at the struts source, you can see the following code: in Org.apache.struts.util.PropertyMessageResources Class, like the following code:
Through this code, you can see
A,. properties extension is written to death in the code, so the resource file must use this extension
B, struts is not simply to find application.properties files, but first find application, assigned to the name variable and then add the underscore "_", and then add Localekey (such as Zh,en), And then Add. properties
C, after confirming the filename, struts used the ClassLoader class getResourceAsStream method to get a InputStream
D, then struts uses the load method of the Java.util.Properties class to read all the resources in the resource file and put it in a hashmap.
E, then struts can take out different message to the foreground according to the key value
The Set up to load the property resource for this locale key, if we can
String name = Config.replace ('. ', '/');
if (localekey.length () > 0) {
Name + + "_" + Localekey;
}
Name = = ". Properties";
InputStream is = null;
Properties Props = new properties ();
Load the specified property resource
if (log.istraceenabled ()) {
Log.trace ("Loading resource '" + name + "");
}
ClassLoader ClassLoader = Thread.CurrentThread (). Getcontextclassloader ();
if (ClassLoader = = null) {
ClassLoader = This.getclass (). getClassLoader ();
}
is = Classloader.getresourceasstream (name);
if (is!= null) {
try {
Props.load (IS);
catch (IOException e) {
Log.error ("Loadlocale ()", e);
finally {
try {
Is.close ();
catch (IOException e) {
Log.error ("Loadlocale ()", e);
}
}
}