Support for JSP Spring ApplicationContext internationalization and springmvcjsp Internationalization

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.