<fmt:requestEncoding> Tag
The <fmt:requestEncoding>
tag is used to specify the form encoding type returned to the web application.
Syntax
<fmt:requestEncoding value="<string>"/>
Attributes
Attribute | Description | Required | Default Value |
---|---|---|---|
key | The name of the character encoding set used to decode request parameters | Yes | None |
Use the <fmt:requestEncoding>
tag to specify the character set used to decode data from forms. This tag is necessary when the character set is not ISO-8859-1. Since most browsers do not include the Content-Type header in their requests, this tag is required.
The purpose of the <fmt:requestEncoding>
tag is to specify the Content-Type of the request. You must specify a Content-Type, even if the response is encoded via the contentType attribute of the Page directive. This is because the actual locale of the response may differ from that specified by the Page directive.
If the page contains I18N-capable formatting actions that set the locale attribute of the response (by calling the ServletResponse.setLocale() method), any character set specified in the page will be overridden.
Example Demonstration
Example
<%@ 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 Tag</title>
</head>
<body>
<fmt:requestEncoding value="UTF-8" />
<fmt:setLocale value="es_ES"/>
<fmt:setBundle basename="com.tutorialpro.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>
Output
Uno
Dos
Tres