• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • 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)
  • 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)

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

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

 

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

Category: Java EETag: 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.

Previous Post: « JSTL Format fmt:message Tag
Next Post: JSTL XML Tags Library »

Reader Interactions

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.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

New Features in Spring Boot 1.4

Difference Between @RequestParam and @PathVariable in Spring MVC

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact