<fmt:requestEncoding> 标签

JSP 标准标签库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()方法),任何在页面中指定的编码集将会被覆盖。



实例演示

<%@ 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:requestEncoding value="UTF-8" />
<fmt:setLocale value="es_ES"/>
<fmt:setBundle basename="com.icodebang.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>

运行结果如下:

Uno
Dos
Tres

JSP 标准标签库JSP 标准标签库

0 个评论

要回复文章请先登录注册