<div dir="ltr" style="text-align: left;">
<div dir="ltr" style="text-align: left;">
<div dir="ltr" style="text-align: left;">
<div dir="ltr" style="text-align: left;">
<p>In this tutorial we will discuss about the control tags in struts2. The Struts 2 tags have a set of tags that make it easy to control the flow of page execution. Following is the list of important Struts 2 Control Tags:<br />
<b></b></p>
<h2><b><a href="https://dineshonjava.com/struts-2-if-and-else-tags/" target="_blank" rel="noopener">The if and else tags</a>:</b></h2>
<p>These tags perform basic condition flow found in every language. &#8216;If&#8217; tag could be used by itself or with &#8216;Else If&#8217; Tag and/or single/multiple &#8216;Else&#8217; Tag as shown below:</p>
<pre class="highlight"><;s:if test="%{#name=='Dinesh'}">; 
 This is Male Category 
 <;/s:if>; 
 <;s:elseif test="%{#name=='Sweety'}">; 
 This is Female Category 
 <;/s:elseif>; 
 <;s:else>; 
 Other Category 
 <;/s:else>; 
</pre>
<p><b><a href="https://dineshonjava.com/struts-2-if-and-else-tags/" target="_blank" rel="noopener">Click here for detail example.</a></b></p>
<h2><a href="https://dineshonjava.com/struts-2-iterator-tag-example/" target="_blank" rel="noopener"><b>The iterator tags:</b></a></h2>
<p>These iterator will iterate over a value. An iterable value can be any of: <i><b>java.util.Collection, java.util.Iterator</b></i>. While iterating over an iterator, you can use Sort tag to sort the result or SubSet tag to to get a sub set of the list or array.</p>
<p>The following example retrieves the value of the getUsers() method of the current object on the value stack and uses it to iterate over. The tag prints out the current value of the iterator.</p>
</div>
<pre class="highlight"><;s:iterator value="users">; 
 <;p>;User Name is: <;s:property name="userName"/>;<;/p>; 
<;/s:iterator>; 
</pre>
<p><b><a href="https://dineshonjava.com/struts-2-iterator-tag-example/" target="_blank" rel="noopener">Click here for detail Example</a></b></p>
<h2><b><a href="https://dineshonjava.com/struts-2-append-tag-example/" target="_blank" rel="noopener">The append tag</a>:</b></h2>
<p>These append tag take two or more lists as parameters and append them all together as shown below:</p>
<pre class="highlight"><;s:append var="myAppendIterator">; 
 <;s:param value="%{myList1}" />; 
 <;s:param value="%{myList2}" />; 
 <;s:param value="%{myList3}" />; 
<;/s:append>; 
<;s:iterator value="%{#myAppendIterator}">; 
 <;s:property />; 
<;/s:iterator>; 
</pre>
<p><b><a href="https://dineshonjava.com/struts-2-append-tag-example/" target="_blank" rel="noopener">Click here for detail Example.</a></b></p>
<h2><b><a href="https://dineshonjava.com/struts-2-merge-tag-example/" target="_blank" rel="noopener">The merge tag</a>:</b></h2>
<p>These merge tag take two or more lists as parameters and merge them all together as shown below:</p>
<pre class="highlight"><;s:merge var="myMergedIterator">; 
 <;s:param value="%{myList1}" />; 
 <;s:param value="%{myList2}" />; 
 <;s:param value="%{myList3}" />; 
<;/s:merge>; 
<;s:iterator value="%{#myMergedIterator}">; 
 <;s:property />; 
<;/s:iterator>; 
</pre>
<p><b><a href="https://dineshonjava.com/struts-2-merge-tag-example/" target="_blank" rel="noopener">Click here for Detail Example.</a></b></p>
<h2><b><a href="https://dineshonjava.com/struts-2-generator-tag/" target="_blank" rel="noopener">The generator tag</a>:</b></h2>
<p>These generator tag generates an iterator based on the val attribute supplied. Following generator tag generates an iterator and print it out using the iterator tag.</p>
<pre class="highlight"><;s:generator val="%{'dinesh,sweety,aadesh,vinesh,sandhya'}">; 
 <;s:iterator>; 
 <;s:property />;<;br/>; 
 <;/s:iterator>; 
<;/s:generator>; 
</pre>
<p><b><a href="https://dineshonjava.com/struts-2-generator-tag/" target="_blank" rel="noopener">Click here for detail Example</a></b>.</p>
<h2><b><a href="https://dineshonjava.com/struts2-sort-tag-example/" target="_blank" rel="noopener">The sort tag</a>:</b></h2>
<p>Struts 2 sort tag is used to sort a List using a java.util.Comparator. In this example, we will create 6 Users objects and add all into an ArrayList, and use the sort tag to sort the ArrayList based on the User’s property.</p>
<pre class="highlight"><;s:sort comparator="#userNameComparator" source="users">; 
<;ol>; 
<;s:iterator>; 
 <;li>;<;s:property value="userName" />;, 
 <;s:property value="userName" />;, 
 <;s:property value="age" />; 
 <;/li>; 
<;/s:iterator>; 
<;/ol>; 
<;/s:sort>; 
</pre>
<p><b><a href="https://dineshonjava.com/struts2-sort-tag-example/" target="_blank" rel="noopener">Click here for detail Example.</a></b></p>
</div>
<h2><b><a href="https://dineshonjava.com/struts2-subset-tag-example/" target="_blank" rel="noopener">The subset tag</a>:</b></h2>
<p>A JSP page to show the use of subset tag to output a subset of an iterator</p>
<pre class="highlight"><;s:subset source="myList">; 
 <;s:iterator>; 
 <;s:property />;<;br>; 
 <;/s:iterator>; 
 <;/s:subset>; 
</pre>
</div>
<p><b><a href="https://dineshonjava.com/struts2-subset-tag-example/" target="_blank" rel="noopener">Click here for detail Example.</a></b></p>
<p> ;</p>
<div style="background-color: pink; border-width: thin; text-align: center;"><b><;<;<a href="https://dineshonjava.com/annotations-in-struts2-with-example/">Previous</a> <;<; || <a href="https://dineshonjava.com/struts-2-baby-step-to-learn/">Index </a>|| >;>;<a href="https://dineshonjava.com/struts-2-if-and-else-tags/">Next</a> >;>;</b></div>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/annotations-in-struts2-with-example/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/struts-2-if-and-else-tags/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '377'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…