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

Example of push tag in struts2.2.1

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" %> ADS_TO_REPLACE_1

<html>

<head><title>Struts2.2.1_push_Tag_Example1</title>

</head>ADS_TO_REPLACE_2

<body><h2>Struts2.2.1_push_Tag_Example1</h2>

<hr>Hello<s:a href="PushAction.action">pushAction</s:a>

</body>ADS_TO_REPLACE_3

</html>

2-PushTagAction.java

package roseindia.action;

import com.opensymphony.xwork2.ActionSupport;ADS_TO_REPLACE_4

public class PushTagAction extends ActionSupport {

public String execute() {

return SUCCESS;}ADS_TO_REPLACE_5

}

3-EmployeeBean.java

package roseindia.bean;

public class EmployeeBean {ADS_TO_REPLACE_6

private String emp_name ="Bharat";

private String address="Bareilly";

public String getEmp_name() {ADS_TO_REPLACE_7

return emp_name;}

public void setEmp_name(String empName) {

emp_name = empName;}ADS_TO_REPLACE_8

public String getAddress() {

return address;}

public void setAddress(String address) {ADS_TO_REPLACE_9

this.address = address;}

}

4_struts.xml

<struts>

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

<action name="PushAction" class="roseindia.action.PushTagAction">

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

</action>ADS_TO_REPLACE_11

</package>

</struts>

5_pushResult.jsp

<html>

<head> ADS_TO_REPLACE_12

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

<title>struts2.2.1_push_tag_Example</title>

<STYLE type="text/css">ADS_TO_REPLACE_13

b{color:olive;}

</STYLE>

</head><body><h2>struts2.2.1_push_tag_Example</h2>ADS_TO_REPLACE_14

<hr/><b>Simple </b><br/><br/>

<s:bean name="roseindia.bean.EmployeeBean" var="empBean">

Name : <s:property value="#empBean.emp_name"/><br/> ADS_TO_REPLACE_15

Address : <s:property value="#empBean.address"/>

</s:bean>

<hr/><b>Using push tag</b><br/><br/>ADS_TO_REPLACE_16

<s:push value="#empBean">

Name : <s:property value="emp_name"/><br/>

Address : <s:property value="address"/>ADS_TO_REPLACE_17

</s:push>

</body>

</html>

 

indexJsp.gifADS_TO_REPLACE_18

pushResult.gif

ADS_TO_REPLACE_19

Download Select Source Code


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

Advertisements

Ads

Ads

 
Advertisement null

Ads