国际化:
写对应的资源文件.properties
资源文件名称_语言编码_国家编码.properties
abc_zh_CN.properties
abc_en_US.properties
key=value
步骤:
1.编写国际化的资源
abc_zh_CN.properties
id=\u5BF9\u65B9\u53CD\u6297
name=\u51E1\u8FBE\u53D1
abc_en_US.properties
id=ID
name=NAME
2.告知spring mvc所使用的资源文件,并且值得注意的是spring mvc是通过id值查找底层国际化资源,所以要加上id=messageSource,因为spring mvc不通过类型注入。
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="abc"/>
</bean>
3.在jsp页面加入标签
JSTL:利用标签代替复杂的java代码
如:core
fmt标签中的message中的key来调用国际化资源
JSTL标签得自己下载,加入WEB-INF中,配置方法如下:
http://www.runoob.com/jsp/jsp-jstl.html
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<fmt:message key="id"></fmt:message>
<br/>
<br/>
<fmt:message key="name"></fmt:message>
</body>
</html>
效果:
问题
中文的界面还是乱码,但是英文正常。试了很多方法还是没成功。
这一节课失败
~~~~(>_<)~~~~