Latest web development tutorials

<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.w3big.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標準標籤庫