<fmt:requestEncoding> 标签

<fmt:requestEncoding> 标签JSP 标准标签库

<fmt:requestEncoding> 标签用来指定返回给Web应用程序的表单编码类型。

语法格式

<fmt:requestEncoding value="<string>"/>

属性

<fmt:requestEncoding> 标签有如下属性:
属性描述是否必要默认值
key 字符编码集的名称,用于解码request参数

使用<fmt:requestEncoding> 标签来指定字符集,用于解码来自表单的数据。在字符集不是 ISO-8859-1 时必须使用这个标签。由于大多数浏览器在它们的请求中不包含 Content-Type 头,所以需要这个标签。

<fmt:requestEncoding> 标签的目的就是用来指定请求的 Content-Type。您必须指定一个 Content-Type,就算 response 是通过 Page 指令的 contentType 属性来编码。这是因为 response 的实际区域可能与 Page 指令所指定的不同。

如果页面包含 I18N-capable 格式行为用于设置 response 的 locale 属性(通过调用 ServletResponse.setLocale() 方法),任何在页面中指定的编码集将会被覆盖。



实例演示

实例

<%@ pagelanguage="java"contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><%@ tagliburi="http://java.sun.com/jsp/jstl/core"prefix="c" %><%@ tagliburi="http://java.sun.com/jsp/jstl/fmt"prefix="fmt" %><html><head><title>JSTL fmt:requestEncoding 标签</title></head><body><fmt:requestEncodingvalue="UTF-8"/><fmt:setLocalevalue="es_ES"/><fmt:setBundlebasename="com.runoob.Example"var="lang"/><fmt:messagekey="count.one"bundle="${lang}"/><br/><fmt:messagekey="count.two"bundle="${lang}"/><br/><fmt:messagekey="count.three"bundle="${lang}"/><br/></body></html>

运行结果如下:

Uno
Dos
Tres

<fmt:requestEncoding> 标签JSP 标准标签库