Support for JSP Spring ApplicationContext internationalization and springmvcjsp Internationalization
JSP Spring ApplicationContext internationalization support
1. The ApplicationContext interface inherits the MessageResource interface. Therefore, you can use ApplicationContext as a spring container to use international resource files.
2. Two methods are defined in the MessageResource interface for internationalization:
String getMessage(String param,Object[] args,Locale loc) ;String getMessage(String param,Object[] args,String default,Locale loc) ;
ApplicationContext is internationalized through these two methods.
3. principle of international support: when the application creates ApplicationContext, Spring automatically searches for the Bean instance named messageSource in the configuration file. If this instance is found, the call of the above two internationalized methods will be handed over to the Bean instance implementation class; if not found, it will be searched up along the parent class; if not found, the system will create an empty StaticMessageSource Bean, which can be called by the preceding two methods, but is empty.
4. The ResourceBundleMessageSource class is usually used in Spring to configure the messageSource Bean. When configuring this Bean, you need to provide a parameter basenames to specify the basic Name of the international resource file used. The parameter value is of the list type. Therefore, you need to use the element to provide the parameter value.
<Bean name = "messageSource" class = "'org. springframework. context. support. resourceBundleMessageSource "> <property name =" basenames "> <list> <value> message </value> </list> </property> </bean> <! -- Provide the resource file --> // message_zh_CN.propertieswelcome = {0}. Welcome! Now Beijing Time: {1} // message_en_US.propertieswelcome = {0}, welcome! Now is: {1} <! -- Call in the main program --> String name = act. getMessage ("welcome", new String [] {"success", new Date ()}, Locale. getDefault (Locale. category. FORMAT ));
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!