Struts - SPLessons

Struts 2 Property Tags

Chapter 11

SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Struts 2 Property Tags

Struts 2 Property Tags

shape Description

Struts 2 Property Tags, While developing on the projects, developer needs to to write the code, then some tags will help to reduce the code where each and every tag will have its own functionality but all the tags functionality is same but their usage may be different in technologies. Struts 2 have some set of tags. Using these tags, user can easily execute the flow of page execution. Struts 2 has the great feature that can integrate with other frameworks such as hibernate, tiles, spring, tiles, Ajax. Following are the different tags available in Struts 2 will help to reduce the programming length.

Property Tag

shape Description

The Struts 2 data tags are mostly used to display the manipulate data on a page, Struts 2 Property Tags is the data tag. These property tag is used to get the property of a value, which is by default defined in stack.

<s:property value=”name”/>

Following is an example which describes more about the property tag and how it works functionally.

public class Person {
	private String name = "Name from"; 
	public String getName() {
		return name;


Here just declared the text by using String and Get method has been performed to get the data.

import com.opensymphony.xwork2.ActionSupport;
public class PropertyTagAction extends ActionSupport{
	private String name = "Name from"; 
	public String getName() {
		return name;

	public String execute() throws Exception {
		return SUCCESS;

The execute() will execute the String and returns the success.

<%@ taglib prefix="s" uri="/struts-tags" %>
<h1>Struts 2 property tag example</h1>

<h2>1. Call getName() from</h2> 
<s:property value="name" />

<h2>2. Call getName() from</h2> 
<s:bean name="com.splessons.Person" var="personBean" />
<s:property value="" />


The getName() is used to get the name from and

<?xml version="1.0" encoding="UTF-8" ?>
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 	<constant name="struts.devMode" value="false" />
	<package name="default" namespace="/" extends="struts-default">
		<action name="propertyTagAction" 
			class="com.splessons.PropertyTagAction" >
			<result name="success">pages/property.jsp</result>

By default, the development mode is disabled, because it has a significant impact on performance, since the entire configuration will be reloaded on every request.

The development mode is only suitable in a development or debugging environment. In a production environment, you have to disable it. It will cause significant impact on performance, because the entire application configuration and properties files will be reloaded on every request and extra logging and debugging information will also be provided.

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "" >

  <display-name>Struts 2 Web Application</display-name>

When compile the program output will be as follows.


shape Key Points

  • Struts 2 Property Tags is by default defined in stack.
  • Struts 2 Property Tags may have separate file needs to be kept along with HTML, JSP files.