Struts2.2.1 i18n Tag Example
Posted on: January 6, 2011 at 12:00 AM
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.ADS_TO_REPLACE_1

<%@ 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">ADS_TO_REPLACE_2

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

<html>

<head>ADS_TO_REPLACE_3

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

<title>i18n Tag Example</title>

</head>ADS_TO_REPLACE_4

<body>

<s:i18n name="i18nTag">

<s:text name="i18nTag" />ADS_TO_REPLACE_5

</s:i18n>

</body>

</html>

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

<%@ 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"
>ADS_TO_REPLACE_7

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

<html>

<head>ADS_TO_REPLACE_8

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

<title>i18n Tag Example</title>

</head>ADS_TO_REPLACE_9

<body>

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

</body>ADS_TO_REPLACE_10

</html>

The Struts mapping file Struts.xml is as follows-

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

<!DOCTYPE struts PUBLICADS_TO_REPLACE_11

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

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

<struts>ADS_TO_REPLACE_12

<constant name="struts.enable.DynamicMethodInvocation"

value="false" />

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

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

value="ApplicationResources" />

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

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

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

</action>ADS_TO_REPLACE_15

</package>

</struts>

The i18ntag.properties file is follows-

i18nTag="This i18 Tag implementation"

The action class i18nTag.java is as follows.ADS_TO_REPLACE_16

package roseindia;

import com.opensymphony.xwork2.ActionSupport;

public class i18nTag extends ActionSupport{ADS_TO_REPLACE_17

public String execute() throws Exception {

return SUCCESS;

}ADS_TO_REPLACE_18

}

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

Output:-

ADS_TO_REPLACE_19

Download Select Source Code


Related Tags for Struts2.2.1 i18n Tag Example:

Advertisements

Ads

Ads

 
Advertisement null

Ads