如何在 JSP 中将键映射到本地化消息并执行参数替换?

jspjava 8object oriented programmingprogramming

<fmt: message> 标签将键映射到本地化消息并执行参数替换。

属性

<fmt: message> 标签具有以下属性 −

属性描述必需Default
keyMessage key to retrieveNoBody
bundleResource bundle to useNoDefault bundle
varName of the variable to store the localized messageNoPrint to page
scopeThe scope of the variable to store the localized messageNoPage

示例

<%@ 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>

You will receive the following result −

One
Two
Three

相关文章