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.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>Text Tag Example</title>

</head>ADS_TO_REPLACE_4

<body>

Here is the messages.<br>

<s:i18n name="TextTag">ADS_TO_REPLACE_5

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

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

<s:text name="message3" />ADS_TO_REPLACE_6

</s:i18n>

</body>

</html>

The Struts mapping file Struts.xml is as follows-ADS_TO_REPLACE_7

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

<!DOCTYPE struts PUBLIC

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

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

<struts>

<constant name="struts.enable.DynamicMethodInvocation"ADS_TO_REPLACE_9

value="false" />

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

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

value="ApplicationResources" />

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

<action name="TextTag" class="roseindia.TextTag">ADS_TO_REPLACE_11

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

</action>

</package>ADS_TO_REPLACE_12

</struts>

The TextTag.properties file is follows-

message1=Welcome Friends

message2=This is text tag exampleADS_TO_REPLACE_13

message3=Thank You for visit.

The action class TextTag.java is as follows.

package roseindia;

import com.opensymphony.xwork2.ActionSupport;ADS_TO_REPLACE_14

public class TextTag extends ActionSupport{

public String execute() throws Exception {

return SUCCESS;ADS_TO_REPLACE_15

}

}

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

Output:-ADS_TO_REPLACE_16

Download Select Source Code


Related Tags for Struts2.2.1 text Tag Example:

Advertisements

Ads

 
Advertisement null

Ads