The <fmt: requestEncoding> tag is used to set the character encoding of a request.
The Syntax Of <fmt: requestEncoding> Tag
<fmt: requestEncoding attributes/>
Attributes of <fmt: requestEncoding> Tag
value: The character encoding is further used to decode the request parameter.
Example
In first ResourceBundle class we have put color name
Listing 1: EncCode_gg.java
package javabeat.net; import java.util.ListResourceBundle; public class EncCode_gg extends ListResourceBundle { public Object[][] getContents() { return contents; } Static final Object[][] contents = { {"color.blue", "Blue"}, {"count.green", "Green"}, {"count.white", "White"}, }; }
The another ResourceBundle contains color name in spanish language:
Listing 2: EncCode_bb.java
package javabeat.net; import java.util.ListResourceBundle; public class EncCode_bb extends ListResourceBundle { public Object[][] getContents() { return contents; } static final Object[][] contents = { {"color.blue", "Azul"}, {"color.green", "Verde"}, {"color.white", "Blanco"}, }; }
Listing 3: example.jsp
<%@ 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 Tag</title> </head> <body> <fmt:requestEncoding value="UTF-8" /> <fmt:setLocale value="bb"/> <fmt:setBundle basename="javabeat.net.EncCode" var="lang"/> <fmt:message key="color.blue" bundle="${lang}"/><br/> <fmt:message key="color.green" bundle="${lang}"/><br/> <fmt:message key="color.white" bundle="${lang}"/><br/> </body> </html>
Details of the Code
<fmt:requestEncoding value=”UTF-8″ /> is used to for the decoding the data as we can see in the above example, we have encoded the data and later in jsp file by using the requestEncoding tag we have decoded it in Spanish language.
- Save this file as example.jsp in your eclipse IDE.
- Now select this jsp file, right mouse click and select Run as ->Run on server
Output
When the execution process is completed successfully we will get the following output :
Previous Tutorial : JSTL Format fmt:message Tag :: Next Tutorial : JSTL XML Tags Library