Struts 2 framework param tag example
Struts 2 framework param tag example
The struts2 framework provide param tag to use parameter value. The parameter value define in two way first through value attribute and second param tag.<s:bean name="" var="">
<s:param name="" value=""></s:param>
</s:bean>
The struts 2.0 framework provide param tag which are following,<s:bean name="org.r4r.Student" var="student">
<s:param name="name" value="mukund"></s:param>
</s:bean>
Directory Structure of <s:param> tag Example in Struts 2.0 Using MyEclipse IDE
index.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<h1>Param tag example in struts2 framework</h1>
<s:bean name="org.r4r.Course" var="mycourse">
<s:param name="courseName">MCA</s:param>
</s:bean>
<s:bean name="org.r4r.Student" var="studentinfo">
<s:param name="name">Mukund Singh</s:param>
<s:param name="paper">Java</s:param>
<s:param name="course" value="#mycourse"></s:param>
</s:bean>
<h3>Student Details</h3>
<ol>
<li>Student Name: <s:property value="#studentinfo.name" /></li>
<li>Student Paper: <s:property value="#studentinfo.paper" /></li>
<li>Student Course: <s:property value="#studentinfo.courseName" /></li>
</ol>
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.Student">
<result name="success">/index.jsp</result>
</action>
</package>
</struts>
Course.java
package org.r4r;
public class Course {
String courseName;
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
}
student.java
package org.r4r;
public class Student {
String name;
String paper;
Course course;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPaper() {
return paper;
}
public void setPaper(String paper) {
this.paper = paper;
}
public Course getCourse() {
return course;
}
public void setCourse(Course course) {
this.course = course;
}
public String getCourseName(){
return this.course.getCourseName();
}
}
Output