JSTL - Core <fmt:requestEncoding> Tag


The <fmt:requestEncoding> tag is used to specify the encoding type used by forms that post data back to the Web application.


The <fmt:requestEncoding> tag has the following attributes −

Attribute Description Required Default
key Name of character encoding you want to apply when decoding request parameters. Yes None

You use the <fmt:requestEncoding> tag when you want to specify character encoding for decoding data posted from forms. This tag must be used with character encodings that are different from ISO-8859-1. The tag is required since most browsers do not include a Content-Type header in their requests.

The purpose of the <fmt:requestEncoding> tag is to specify the content type of the request. You must specify the content type, even if the encoding of the page generating the response is specified via the contentType attribute of a page directive. This is because the response's actual locale (and thus character encoding) may differ from the value specified in the page directive.

If the page contains an I18N-capable formatting action that sets the response's locale (and thus character encoding) by calling ServletResponse.setLocale(), any encoding specified in the page directive will be overridden.


<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/fmt" prefix = "fmt" %>

      <title>JSTL fmt:message Tag</title>

      <fmt:requestEncoding value = "UTF-8" />
      <fmt:setLocale value = "es_ES"/>
      <fmt:setBundle basename = "com.tutorialspoint.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/>


You will receive the following result −