i18n tag example in struts2 framework

i18n tag example in struts2 framework

Previous Home Next

 

The Struts2 framework provide "i18n" tag, through this tag get the message from any declared resource bundle for example properties file. This tag read the content which are written on the properties file and show output on the web browser.
Syntax of i18n tag:-
<s:i18n name="">
<s:text name=""></s:text>
</s:i18n>

The struts2 framework tag library provide following i18n tag,
<s:i18n name="org.r4r.hello">
<s:text name="i18n.msg"></s:text>
</s:i18n>
 

Directory Structure of <s:i18n> tag Example in Struts 2.0 Using MyEclipse IDE



index.jsp

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

<h2>i18n Tag example in struts2 framework</h2>
<s:i18n name="org.r4r.hello">
<s:text name="i18n.msg"></s:text>
</s:i18n>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  
  <filter>
  <filter-name>f1</filter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  </filter>
  <filter-mapping>
  <filter-name>f1</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration
2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="demo" extends="struts-default">
<action name="" class="org.r4r.I18NTagAction">
<result name="success" type="dispatcher">/index.jsp</result>
</action>
</package>
</struts>

I18NTagAction.java

package org.r4r;

public class I18NTagAction {
	public String execute(){
		return "success";
	}

}

hello.properties

i18n.msg = "This is a message from I18nTagAction.properties"

Output






Previous Home Next