<fmt:message> 标签

约 849 字 更新于 2026-11-18 5iyo.com

<fmt:message> 标签

<fmt:message>标签映射一个关键字给局部消息,然后执行参数替换。

语法格式


<fmt:message

   key="<string>"

   bundle="<string>"

   var="<string>"

   scope="<string>"/>

属性

<fmt:message>标签有如下属性:

属性 描述 是否必要 默认值
key 要检索的消息关键字 否 Body
bundle 要使用的资源束 否 默认资源束
var 存储局部消息的变量名 否 Print to page
scope var属性的作用域 否 Page


实例演示


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

<title>JSTL fmt:message 标签</title>

</head>

<body>



<fmt:setLocale value="en"/>

<fmt:setBundle basename="com.runoob.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