jsp:jstl标签库国际化 fmt

首先资源文件目录是:src/man/sources (这是它默认的资源文件)

i18n_en_US.properties文件内容

copyright=Copyright u00A9 2013
language=language
bookname=HTTP by picture

  

jsp内容,因为资源文件还有一层目录,所以bundle的basename需要加上这层目录:i18n.i18n

i18n(目录).i18n开头名

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>


<!--指定区域语言-->
<fmt:setLocale value="en_US"/>
<!-- 指定使用basename为globalMessages的资源文件,也即资源文件第一个单词为globalMessages-->
<fmt:bundle basename="i18n.i18n">
<fmt:message key="language"></fmt:message>
<fmt:message key="bookname"></fmt:message>
</fmt:bundle>

</body>
</html>

  

原文地址:https://www.cnblogs.com/achengmu/p/8324667.html