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

Ask Questions?

View Latest Questions


 
 

Struts2.2.1 text Tag Example
Posted on: January 11, 2011 at 12:00 AM
Advertisement
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"

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

</head>

<body>

Here is the messages.<br>

<s:i18n name="TextTag">

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

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

<s:text name="message3" />

</s:i18n>

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

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

</action>

</package>

</struts>

The TextTag.properties file is follows-

message1=Welcome Friends

message2=This is text tag example

message3=Thank You for visit.

The action class TextTag.java 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-

Output:-

Download Select Source Code


Related Tags for Struts2.2.1 text Tag Example:


DMCA.com