如何在同一个 JSP 中使用多个资源包?


<fmt:setBundle> 标记用于加载资源包并将它存储在指定的范围变量或包配置变量中。

属性

<fmt:setBundle> 标记有如下属性 -

属性描述必需默认
basename作为有作用域或配置变量显示的资源包系列的基本名称
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:setBundle 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

更新时间: 2019 年 7 月 30 日

257 次观看

开启你的 职业生涯

获得完成课程的认证

开始学习
广告
© . All rights reserved.