如何将键与本地化信息对应,并在 JSP 中执行参数替换?
<fmt: message> 标记将键映射到本地化信息并执行参数替换。
属性
<fmt: message> 标记具有以下属性 -
| 属性 | 说明 | 必需 | 默认值 |
|---|---|---|---|
| key | 检索的消息键 | 否 | 正文 |
| bundle | 要使用的资源包 | 否 | 默认包 |
| var | 存储本地化消息的变量名称 | 否 | 打印到页面 |
| scope | 存储本地化消息的变量的范围 | 否 | 页面 |
示例
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/fmt" prefix = "fmt" %>
<html>
<head>
<title>JSTL fmt:message Tag</title>
</head>
<body>
<fmt:setLocale value = "en"/>
<fmt:setBundle basename = "com.tutorialspoint.Example" var = "lang"/>
<fmt:message key = "count.one" bundle = "${lang}"/><br/>
<fmt:message key = "count.two" bundle = "${lang}"/><br/>
<fmt:message key = "count.three" bundle = "${lang}"/><br/>
</body>
</html>您将收到以下结果 -
One Two Three
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP