JavaBeat

  • Home
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Privacy
  • Contact Us

JSTL Format fmt:requestEncoding Tag

February 27, 2014 by Krishna Srinivasan Leave a Comment

The <fmt: requestEncoding> tag is used to set the character encoding of a request.

The Syntax Of <fmt: requestEncoding> Tag

[code lang=”html”]
<fmt: requestEncoding attributes/>
[/code]

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

[code lang=”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"},
};
}
[/code]

The another ResourceBundle contains color name in spanish language:

Listing 2: EncCode_bb.java

[code lang=”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"},
};
}
[/code]

Listing 3: example.jsp

[code lang=”html”]
<%@ 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>
[/code]

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 :
fmt requestEncoding output

 

Previous Tutorial : JSTL Format fmt:message Tag :: Next Tutorial : JSTL XML Tags Library

Filed Under: Java EE Tagged With: JSTL Tutorials

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow Us

  • Facebook
  • Pinterest

As a participant in the Amazon Services LLC Associates Program, this site may earn from qualifying purchases. We may also earn commissions on purchases from other retail websites.

JavaBeat

FEATURED TUTORIALS

Answered: Using Java to Convert Int to String

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Copyright © by JavaBeat · All rights reserved