如何在同一個 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 次觀看

開啟你的 職業生涯

獲得完成課程的認證

開始學習
廣告