In this example, you will see the use of push tag of struts2.2.1 framework. The push tag push a value onto the to of stack. So it can access easily by using first-level of OGNL expression language..
Directory structure of push tag example.![]() |
1- index.jsp
|
<%@taglib uri="/struts-tags" prefix="s" %> <html> <head><title>Struts2.2.1_push_Tag_Example1</title> </head> <body><h2>Struts2.2.1_push_Tag_Example1</h2> <hr>Hello<s:a href="PushAction.action">pushAction</s:a> </body> </html> |
2-PushTagAction.java
|
package roseindia.action; import com.opensymphony.xwork2.ActionSupport; public class PushTagAction extends ActionSupport { public String execute() { return SUCCESS;} } |
3-EmployeeBean.java
|
package roseindia.bean; public class EmployeeBean { private String emp_name ="Bharat"; private String address="Bareilly"; public String getEmp_name() { return emp_name;} public void setEmp_name(String empName) { emp_name = empName;} public String getAddress() { return address;} public void setAddress(String address) { this.address = address;} } |
4_struts.xml
|
<struts> <package name="roseindia" extends="struts-default" namespace="/"><action name="PushAction" class="roseindia.action.PushTagAction"> <result name="success">pushResult.jsp</result> </action></package> </struts> |
5_pushResult.jsp
|
<html> <head> <%@taglib uri="/struts-tags" prefix="s" %> <title>struts2.2.1_push_tag_Example</title> <STYLE type="text/css"> b{color:olive;} </STYLE> </head><body><h2>struts2.2.1_push_tag_Example</h2> <hr/><b>Simple </b><br/><br/> <s:bean name="roseindia.bean.EmployeeBean" var="empBean"> Name : <s:property value="#empBean.emp_name"/><br/> Address : <s:property value="#empBean.address"/> </s:bean> <hr/><b>Using push tag</b><br/><br/> <s:push value="#empBean"> Name : <s:property value="emp_name"/><br/> Address : <s:property value="address"/> </s:push> </body> </html> |
indexJsp.gif

pushResult.gif
