Push tag example in Struts2.0 framework

Push tag example in Struts2.0 framework

Previous Home Next

 

The struts2.0 framework tag library provide the push tag to store value in the valuestack at the top position . Through in this tag we are fetch value easily .
<s:push value=" " ></s:push>

The struts2.0 framework provide following push tag example
<s:push value="#personBean" >
   <s:property value="name" > 
<s:property value="address"> 
</s:push>
   
 
 
Directory Structure of <s:push> tag Example in Struts 2.0 Using MyEclipse IDE



index.jsp

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

<h1>Struts 2 push tag example</h1>
 
<s:bean name="org.r4r.Student" var="student" />
<s:push value="#student" >
Name : <s:property value="name" /><br/>
College: <s:property value="college" /><br/>
Course:<s:property value="course"/>
</s:push>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  
  <filter>
  <filter-name>f1</filter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  </filter>
  <filter-mapping>
  <filter-name>f1</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration
2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="demo" extends="struts-default">
<action name="" class="org.r4r.StudentAction">
<result name="success">/index.jsp</result>
</action>
</package>
</struts>

StudentAction.java

package org.r4r;

public class StudentAction {
	public String execute(){
		return "success";
	}

}

student.java

package org.r4r;

public class Student {
	String name="Mukund Singh";
	String college="HIMT";
	String course="MCA";
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getCollege() {
		return college;
	}
	public void setCollege(String college) {
		this.college = college;
	}
	public String getCourse() {
		return course;
	}
	public void setCourse(String course) {
		this.course = course;
	}

}

Output






Previous Home Next