Struts2.2.1 text Tag Example
Posted on: January 11, 2011 at 12:00 AM
The text tag is a generic tag that is used to render a I18n text message.

Struts2.2.1 text Tag Example

The text tag is a generic tag that is used to render a I18n text message.The message must be in a resource bundle with the same name as the action that it is associated with. In practice this means that you should create a properties file in the same package as your Java class with the same name as your class, but with .properties extension.

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

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

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


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

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



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

<title>Text Tag Example</title>



Here is the messages.<br>

<s:i18n name="TextTag">

<s:text name="message1" /><br>

<s:text name="message2" /><br>

<s:text name="message3" />




The Struts mapping file Struts.xml is as follows-

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


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



<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="TextTag" class="roseindia.TextTag">

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




The file is follows-

message1=Welcome Friends

message2=This is text tag example

message3=Thank You for visit.

The action class is as follows.

package roseindia;

import com.opensymphony.xwork2.ActionSupport;

public class TextTag extends ActionSupport{

public String execute() throws Exception {

return SUCCESS;



This Program produces output on the basis of the Text Tag  evaluation, This  give the output as-


Download Select Source Code

Related Tags for Struts2.2.1 text Tag Example:




Advertisement null