If the id attribute is set on the BeanTag, it will place the instantiated bean into the stack's Context.
Add the following code snippet into the struts.xml file.
struts.xml
<action name="beanTag" class="struts2.actionTag"> <result name="success">/pages/genericTags/bean.jsp</result> </action>
Create an action class as shown below:
beanTag.java
package net.struts2; import com.opensymphony.xwork2.ActionSupport; public class beanTag extends ActionSupport { public String execute() throws Exception{ return SUCCESS; } }
create a simple java bean as shown:
companyName.java
package net.struts2; public class companyName { private String name; public void setName(String name){ this.name =name ; } public String getName(){ return name; } }
Now create a jsp page using
beanTag.jsp
<%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>Bean Tag Example!</title> </head> <body> <h1><span style="background-color: #FFFFcc">Bean Tag (Data Tags) Example!</span></h1> <s:bean name="net.struts2.companyName" id="uid"> <s:param name="name">struts2</s:param> <s:property value="%{name}" /><br> </s:bean> </body> </html>