SPRING in ACTION 4th Edition notes-sixth chapter rendering WEB views-003-spring General TAG Library Introduction and <s:message> and Reloadableresourcebundlemessagesource for internationalization

Source: Internet
Author: User

A spring-supported general TAG LIBRARY

1.

Second, to achieve internationalization with <s:message> and Reloadableresourcebundlemessagesource

1. Configure Reloadableresourcebundlemessagesource, which can it has the ability to reload Mes Sage Properties without recompiling or restarting the application.

1  PackageSpittr.web;2 3 ImportOrg.springframework.context.MessageSource;4 ImportOrg.springframework.context.annotation.Bean;5 ImportOrg.springframework.context.annotation.ComponentScan;6 Importorg.springframework.context.annotation.Configuration;7 ImportOrg.springframework.context.support.ReloadableResourceBundleMessageSource;8 ImportOrg.springframework.web.servlet.ViewResolver;9 ImportOrg.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;Ten ImportORG.SPRINGFRAMEWORK.WEB.SERVLET.CONFIG.ANNOTATION.ENABLEWEBMVC; One ImportOrg.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; A ImportOrg.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; - ImportOrg.springframework.web.servlet.view.InternalResourceViewResolver; -  the @Configuration - @EnableWebMvc -@ComponentScan ("Spittr.web") -  Public classWebconfigextendsWebmvcconfigureradapter { +  - @Bean +    Publicviewresolver Viewresolver () { AInternalresourceviewresolver resolver =Newinternalresourceviewresolver (); atResolver.setprefix ("/web-inf/views/"); -Resolver.setsuffix (". JSP"); -     returnResolver; -   } -    - @Override in    Public voidconfiguredefaultservlethandling (Defaultservlethandlerconfigurer configurer) { - configurer.enable (); to   } +    - @Override the    Public voidaddresourcehandlers (Resourcehandlerregistry registry) { *     //TODO auto-generated Method Stub $     Super. Addresourcehandlers (registry);Panax Notoginseng   } -    the @Bean +    PublicMessagesource Messagesource () { AReloadableresourcebundlemessagesource Messagesource = the         NewReloadableresourcebundlemessagesource (); +     //messagesource.setbasename ("File:///users/habuma/messages "); -     //messagesource.setbasename ("messages"); $Messagesource.setbasename ("Classpath:messages"); $Messagesource.setcacheseconds (10); -     returnMessagesource; -   } the   -}

(1) There are 3 forms of the path

Application path: No prefix

Classpath: "Classpath:xxx"

System path: "File:///Users/habuma/messages"

(2) There is another messageresource, to reload the resource file to restart the app

1 @Bean 2  Public Messagesource Messagesource () {3     New Resourcebundlemessagesource (); 4     Messagesource.setbasename ("Messages"); 5     return Messagesource; 6 }

2. Write the resource file and put it in the appropriate path

(1) Default file messages.properties

1 spitter.welcome=welcome to spitter\!

(2) When the client language is Chinese messages_zh_cn.properties

Spitter.welcome=\u6b22\u8fce

3.view Layer Display

1<%@ taglib uri= "Http://java.sun.com/jsp/jstl/core" prefix= "C"%>2<%@ taglib uri= "Http://www.springframework.org/tags" prefix= "s"%>3<%@ page session= "false"%>4<%@ page contenttype= "Text/html;charset=utf-8"%>567<title>Spitter</title>8<link rel= "stylesheet"9Type= "Text/css"Tenhref= "<c:url value="/resources/style.css "/>" > One A<body> -<s:message code= "Spitter.welcome" text= "Welcome"/> -</body> the

4.

SPRING in ACTION 4th Edition notes-sixth chapter rendering WEB views-003-spring General TAG Library Introduction and <s:message> and Reloadableresourcebundlemessagesource for internationalization

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.