Property tag example in Struts2.0 Framework

Property tag example in Struts2.0 Framework

Previous Home Next

 

The struts2.0 framework tag library provide property tag . This tag fetch information which are store in the ValueStack . It means action class push in valuestack and store value in valuestack then property tag fetch value which are store in the valuestack and print on the browser.

<s:property value=" " />  

The following example of property tag which are provided by the struts2.0 framework library
<s:property value="name" />
 
Directory Structure of <s:property> tag Example in Struts 2.0 Using MyEclipse IDE


index.jsp

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

<h1>Property tag example in struts2 framework</h1>
 
<h4>Student name fetch by property tag</h4> 
<s:property value="name" />
 
<h4>Course name fetch by property tag through bean tag</h4> 
<s:bean name="org.r4r.Course" var="course" />
<s:property value="#course.name" />

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" type="dispatcher">/index.jsp</result>
</action>
</package>
</struts>   

StudentAction.java

package org.r4r;

public class StudentAction {
	String name="Mukund Singh";

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	public String execute(){
		return "success";
	}

}

course.java

package org.r4r;

public class Course {
	String name="MCA";

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}

Output






Previous Home Next