출처 : http://struts.apache.org/2.0.12/docs/how-do-i-set-a-global-resource-bundle.html
In Struts 2, resource bundles can be associated with classes. The framework will automatically discover and load class-orientated resource bundles. You can also specify one or more global resource bundles, which would be available to all classes in the application, using either the standard properties file, or a custom listener.
Properties file
Global resource bundles can be specified in the struts.properties configuration file.
struts.properties
struts.custom.i18n.resources=global-messages
![]() | The framework searches the class heirarchy first, then, as a last resource, checks the global resources. |
Multiple resource bundles can be specified by providing a comma-separated list.
struts.properties
struts.custom.i18n.resources=global-messages, image-messages
Listener
Aside from the properties file, a Listener could also be used to load global resource bundles.
ActionGlobalMessagesListener.java
public class ActionGlobalMessagesListener implements ServletContextListener {
private static Logger log = Logger.getLogger(ActionGlobalMessagesListener .class);
private static final String DEFAULT_RESOURCE = "global-messages";
/**
* Uses the LocalizedTextUtil to load messages from the global message bundle.
* @see
javax.servlet.ServletContextListener#contextInitialized(javax.servlet.Servle
tContextEvent)
*/
public void contextInitialized(ServletContextEvent arg0) {
log.info("Loading global messages from " + DEFAULT_RESOURCE);
LocalizedTextUtil.addDefaultResourceBundle(DEFAULT_RESOURCE);
log.info("Global messages loaded.");
}
/**
* @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
*/
public void contextDestroyed(ServletContextEvent arg0) {
// do nothing
}
}
web.xml:
(under listeners section)
web.xml
<listener>
<listener-class>mypackagename.ActionGlobalMessagesListener</listener-class>
</listener>
'JAVA > JSP_Servlet' 카테고리의 다른 글
struts2 tag lib 로 number format 지정 (0) | 2008.11.27 |
---|---|
EOFException: Exception loading sessions from persistent storage (0) | 2008.11.26 |
java windows authentication (0) | 2008.07.23 |
[펌] Ajax Progress + commons fileupload (0) | 2007.12.23 |
HWP 파일 다운로드시 저장하고 보면 잘 되지만 열기 했을 경우 안될때... (0) | 2007.07.05 |