<fmt:requestEncoding> 標簽
<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: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