springmvc中的视图简介,以下为 View 接口的实现类
springmvc中的视图所对应的视图解析器:
1、国际化的文件命名规则
2、实现国际化
2.1、创建资源文件 、、
base_zh_CN.properties
文件中如果包含中文则自动将中文转换为 ASCII 码
原格式为:
resource.welcome=欢迎
resource.hello=你好
resource.welcome=u6B22u8FCE resource.hello=u4F60u597D
base_en_US.properties
resource.welcome=WELCOME resource.hello=HELLO
base.properties
当 base_zh_CN.properties 或 base_en_US.properties 没有对应的 key 值时在此文件中寻找
原格式为:
resource.add=添加
resource.add=u6DFBu52A0
2.2、index,jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
Insert title here
国际化
2.3、控制器类
@Controller
@RequestMapping("/index")
public class WelcomeServlet {
@RequestMapping(value={"/internal"})
public String requestInternal() {
System.out.println("requestInternal");
return "internal";
}
}
2.4、添加依赖
javax.servlet jstl 1.2 taglibs standard 1.1.2
2.5、internal.jsp
注意要添加 taglib 标签
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
Insert title here
2.6、在springmvc.xml 中加载 ResourceBundleMessageSource
bean 的 ID 值只能为 messageSource
2.7、测试
1、当前浏览器语言为:中文
执行结果:
2、更改浏览器语言为:英语(美国)
执行结果:



