Text tag example in struts 2.0 framework

Text tag example in struts 2.0 framework

Previous Home Next

 

The struts2.0 framework tag library provide text tag to get information through resource bundle through action class. This tag get information which are written in properties file.
<s:text name=" " />

The struts 2.0 framework provide following text tag,
<s:text name="name.information" />
 
Directory Structure of <s:text> tag Example in Struts 2.0 Using MyEclipse IDE



index.jsp

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

<h1>Text tag example in struts2 framework</h1>
 
<h3>Name data read in properties file</h3> 
Name: <s:text name="name.msg" />
 
<h3>College data read in properties file</h3> 
College:<s:text name="college.msg" />

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.StudentAction">
<result name="success">/index.jsp</result>
</action>
</package>
</struts>  

StudentAction.java

package org.r4r;

public class StudentAction {
	String name;
	public String execute(){
		return "success";
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
}

StudentAction.properties

name.msg = "Mukund Singh"
college.msg= "Harlal Institute of Management & Technology"

Output






Previous Home Next