Home Struts Struts Struts2.2.1 Tags Struts2.2.1 i18n Tag Example

Ask Questions?

View Latest Questions


 
 

Struts2.2.1 i18n Tag Example
Posted on: January 6, 2011 at 12:00 AM
Advertisement
The i18n tag is used to get the message from any declared resource bundle and place it on the value stack.

Struts2.2.1 i18n Tag Example

The i18n tag is used to get the message from any declared resource bundle and place it on the value stack. This allows the text tag to access messages from any bundle, and not just the bundle associated with the current action.

The following Example will shows how to implement the i18n tag in the Struts2.2.1 --

First we create a JSP file named i18nTag.jsp as follows.

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@taglib prefix="s" uri="/struts-tags" %>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>i18n Tag Example</title>

</head>

<body>

<s:i18n name="i18nTag">

<s:text name="i18nTag" />

</s:i18n>

</body>

</html>

The index.jsp file is as follows- This file only contains the hiperlink only.

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"
>

<%@taglib prefix="s" uri="/struts-tags"%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>i18n Tag Example</title>

</head>

<body>

<a href="i18nTag.action">i18n Tag Example</a>

</body>

</html>

The Struts mapping file Struts.xml is as follows-

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

<constant name="struts.enable.DynamicMethodInvocation"

value="false" />

<constant name="struts.devMode" value="false" />

<constant name="struts.custom.i18n.resources"

value="ApplicationResources" />

<package name="default" namespace="/" extends="struts-default">

<action name="i18nTag" class="roseindia.i18nTag">

<result name="success">/i18nTag.jsp</result>

</action>

</package>

</struts>

The i18ntag.properties file is follows-

i18nTag="This i18 Tag implementation"

The action class i18nTag.java is as follows.

package roseindia;

import com.opensymphony.xwork2.ActionSupport;

public class i18nTag extends ActionSupport{

public String execute() throws Exception {

return SUCCESS;

}

}

This Program produces output on the basis of the i18n tag  evaluation, This  give the output as-

Output:-

Download Select Source Code


Related Tags for Struts2.2.1 i18n Tag Example:


DMCA.com