SPRING IN ACTION 第4版笔记-第六章RENDERING WEB VIEWS-003- SPRING的GENERAL TAG LIBRARY简介及用<s:message>和ReloadableResourceBundleMessageSource实现国际化
一、 SPRING支持的GENERAL TAG LIBRARY
1.


二、用<s:message>和ReloadableResourceBundleMessageSource实现国际化
1.配置ReloadableResourceBundleMessageSource,它能it has the ability to reload message properties without recompiling or restarting the application.
package spittr.web; import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver; @Configuration
@EnableWebMvc
@ComponentScan("spittr.web")
public class WebConfig extends WebMvcConfigurerAdapter { @Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
} @Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
} @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// TODO Auto-generated method stub
super.addResourceHandlers(registry);
} @Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource =
new ReloadableResourceBundleMessageSource();
//messageSource.setBasename("file:///Users/habuma/messages");
//messageSource.setBasename("messages");
messageSource.setBasename("classpath:messages");
messageSource.setCacheSeconds(10);
return messageSource;
} }
(1)路径有3种形式
application路径:没有前缀
classpath:"classpath:xxx"
系统路径:"file:///Users/habuma/messages"
(2)还有另一种MessageResource,要重载资源文件要重启应用
@Bean
public MessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("messages");
return messageSource;
}
2.编写资源文件,放到合适的路径
(1)默认文件messages.properties
spitter.welcome=Welcome to Spitter\!
(2)客户端语言是中文时messages_zh_CN.properties
spitter.welcome=\u6B22\u8FCE
3.view层显示
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s" %>
<%@ page session="false" %>
<%@ page contentType="text/html;charset=utf-8" %>
<html>
<head>
<title>Spitter</title>
<link rel="stylesheet"
type="text/css"
href="<c:url value="/resources/style.css" />" >
</head>
<body>
<s:message code="spitter.welcome" text="Welcome" />
</body>
</html>
4.
SPRING IN ACTION 第4版笔记-第六章RENDERING WEB VIEWS-003- SPRING的GENERAL TAG LIBRARY简介及用<s:message>和ReloadableResourceBundleMessageSource实现国际化的更多相关文章
- SPRING IN ACTION 第4版笔记-第六章RENDERING WEB VIEWS-006- 使用thymeleaf(TemplateResolver、SpringTemplateEngine、ThymeleafViewResolver、th:include、th:object、th:field="*{firstName}")
一.在Spring中使用thymeleaf的步骤 1.配置 In order to use Thymeleaf with Spring, you’ll need to configure three ...
- SPRING IN ACTION 第4版笔记-第六章RENDERING WEB VIEWS-002- Spring的JSP标签之form标签(<sf:input><sf:errors><sf:form>)
一. Spring offers two JSP tag libraries to help define the view of your Spring MVC web views. One tag ...
- SPRING IN ACTION 第4版笔记-第六章Rendering web views-001- Spring支持的View Resolver、InternalResourceViewResolver、JstlView
一.Spring支持的View Resolver 二.InternalResourceViewResolver Spring supports JSP views in two ways: Inte ...
- SPRING IN ACTION 第4版笔记-第六章RENDERING WEB VIEWS-005- 使用ApacheTiles(TilesConfigurer、TilesViewResolver、<put-attribute>、<t:insertAttribute>)
一. 1.定义TilesConfigurer.TilesViewResolver的bean 注意有tiles2和tiles3,这里使用tiles3 (1)java形式 package spittr.w ...
- SPRING IN ACTION 第4版笔记-第六章RENDERING WEB VIEWS-004- <s:url>、<s:escapeBody>标签
一.<s:url> <s:url>可以直接生成一个url或url变量,它会在href的基础上加上应用context 1. <a href="<s:url ...
- SPRING IN ACTION 第4版笔记-第七章Advanced Spring MVC-003- 上传文件multipart,配置StandardServletMultipartResolver、CommonsMultipartResolver
一.什么是multipart The Spittr application calls for file uploads in two places. When a new user register ...
- SPRING IN ACTION 第4版笔记-第三章ADVANCING WIRING-005-Bean的作用域@Scope、ProxyMode
一. Spring的bean默认是单例的 But sometimes you may find yourself working with a mutable class that does main ...
- SPRING IN ACTION 第4版笔记-第五章BUILDING SPRING WEB APPLICATIONS-004-以query parameters的形式给action传参数(@RequestParam、defaultValue)
一. 1.Spring MVC provides several ways that a client can pass data into a controller’s handler method ...
- SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-006Spring-Data的运行规则(@EnableJpaRepositories、<jpa:repositories>)
一.JpaRepository 1.要使Spring自动生成实现类的步骤 (1)配置文件xml <?xml version="1.0" encoding="UTF- ...
随机推荐
- web框架--来自维基百科
- 如何用java实现使用电子邮件控制你的电脑
上两天看到一篇文章,用python实现电子邮件控制电脑的有趣的小程序 python 实现微信控制电脑 python版的视频教程 但是苦于自己没接触过python于是想到能不能用java实现,于 ...
- Anddoi 将时间转换为指定时区的时间
import java.text.Format;import java.text.ParseException;import java.text.SimpleDateFormat;import jav ...
- SQL访问EXCEL错误集合
--行集函数 --1, OPENDATASOURCE 环境:WIN7,SQL 2014,OFFICE 2013 SELECT * FROM OPENDATASOURCE('Microsoft.ACE. ...
- aix 计算性内存和文件内存
经过有客户问AIX topas中内存(memory)一项显示的数值含义: MEMORY Real,MB 4096 % Comp 68.9 % Noncomp 22.6 % Clie ...
- ###STL学习--迭代器
点击查看Evernote原文. #@author: gr #@date: 2014-08-23 #@email: forgerui@gmail.com STL中的迭代器. ###stl学习 |--迭代 ...
- java异常练习2
/*有一个圆形和长方形都可以获取面积,对于面积,如果出现非法数值,视为获取面积出现问题问题通过异常来表示.先要对这个程序进行基本的设置 *//*首先想一下,怎么写这个程序基本属性是肯定要的求面积呢?1 ...
- Putty + Vim + Color
Putty + Vim + Color 参考: 1.Using colour schemes with vim and putty 2.Putty的颜色 3.Custom PuTTY Color Th ...
- FileInputStream 与 BufferedInputStream 效率对比
我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3550158.html ,享受整齐的排版.有效的链接.正确的代码缩进.更好的阅读体 ...
- 程序员面试题精选100题(16)-O(logn)求Fibonacci数列[算法]
作者:何海涛 出处:http://zhedahht.blog.163.com/ 题目:定义Fibonacci数列如下: / 0 n=0 f(n)= ...