Example of set tag in struts2.2.1
Posted on: January 7, 2011 at 12:00 AM
in this section, you will see the use of set tag of sstruts2.2.1.

Example of set tag in struts2.2.1

In this tutorial, you will see the use of struts2.2.1 set tag. The set tag is a generic (Data) tag that is used to assign a value of property to another name in a specified scope. It is useful when you wish to assign a variable to a complex expression and then simply reference that variable each time rather than the complex expression. 

Directory structure of set tag example.

 1- index.jsp  

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








<s:a href="setTagAction.action">setTagAction</s:a>



2-SetTagAction .java

package roseindia.action;

import com.opensymphony.xwork2.ActionSupport;

public class SetTagAction extends ActionSupport{

public String execute() throws Exception {

return super.execute();}


3-StudentInfoBean .java

package roseindia.action;

public class StudentInfoBean {

private String name="bharat";

private String age="24";

public String getName() {

return name;}

public void setName(String name) {

this.name = name;}

public String getAge() {

return age;}

public void setAge(String age) {

this.age = age;}




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

<action name="setTagAction" class="roseindia.action.SetTagAction">

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





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





<hr><s:bean name="roseindia.action.StudentInfoBean" var="infoBean">


<h4>Simple use of set tag </h4><br/>

<s:set name="name" value="#infoBean.name" />

<s:set name="age" value="#infoBean.age" />

Student Name :<s:property value="name"/><br/><br/>

Student Age : <s:property value="age"/><br/><br/><hr/>

<h4>Set value of property in session by set tag</h4><br/>

<s:set name="name" value="#infoBean.name" scope="session"/>

<s:set name="age" value="#infoBean.age" scope="session" />

Student Name :<s:property value="#session['name']"/><br/><br/>

Student Age : <s:property value="#session['age']"/><br/><br/>






Download Select Source Code

Related Tags for Example of set tag in struts2.2.1:



Advertisement null