<fmt:requestEncoding> 標籤
<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.zaixian.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