Struts2 bean Tag (data tag)

Usage:
To create a new object on the value stack or ActionContext bean tag is used.
By default it created the object on the ValueStack but you can also create the object on the ActionContext which you can access using #objectName

Attribtues:
name: It is not optional. full name of the class including the package hierarchy.

var: It is optional. Name of the object which you will use for the reference of the object. When you specify the value for the var attribute then your object will be placed on the ActionContext and it will available after the closing tag also, but when you do not provide the value for the var attribute then the object will placed on the ValueStack. Without the var the scope of the created object will remain uptil the closing of the respective tag where it is used.

Here the class of the created object must have the no-argument default constructor. 

Example1:
<s:bean name="com.data.UserData" >
<s:param name="name">hrithik</s:param>
<s:property value="printFullName()"/>
</s:bean>

here the created object will be stored on the ValueStack. So here we can assign value to its 'name' property directly.
In this example you can see that using OGNL we are accessing the method 'printFullName()' of the UserData class.

Example2:
<s:bean name="com.data.UserData" var="userObj">
<s:param name="name">hrithik</s:param>
</s:bean>

Name is : <s:property value="#userObj.name" />
In this example we can access the userObj outside of the tag because we have provided the var attribute. It will create the object on the ActionContext.