天天看點

<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() 方法),任何在頁面中指定的編碼集将會被覆寫。

執行個體示範

執行個體

<%@ 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:requestEncoding 标簽</title>

</head>

<body>

<fmt:requestEncoding value="UTF-8" />

<fmt:setLocale value="es_ES"/>

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

運作結果如下:

Uno
Dos
Tres