How to specify the encoding type used by forms that post data back to the Web application in a JSP?

JSPJava 8Object Oriented ProgrammingProgramming

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 −

keyName of character encoding you want to apply when decoding request parameters.YesNone

You use the <fmt:requestEncoding> tag when you want to specify the 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 = "" prefix = "c" %>
<%@ taglib uri = "" 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 = "" 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 −

Updated on 30-Jul-2019 22:30:25