This tag can be used to parameterize other tags.The parameters can be added with or without a name as key.
when we declare the param tag, the value can be defined in either a value attribute or as text between the start and end tag. Struts behaves a bit different according to these two situations.
This tag has the following two paramters.
name (String) - the name of the parameter
value (Object) - the value of the parameter
The following Example will shows how to implement the ParamTag in the Struts2.2.1 --
First we create a JSP file named ParamTag.jsp as follows.
|
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><! DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><%@ taglib prefix="s" uri="/struts-tags"%>< html>< head>< meta http-equiv="Content-Type" content="text/html; charset=UTF-8">< title>Example of Param Tag</title></ head>< body>< s:bean name="roseindia.ParamTag" var="paramTag"> <s:param name="name">Gyan Singh</s:param> <s:param name="age">25</s:param> <s:param name="status">Single</s:param> <s:param name="birthday">1st March</s:param></ s:bean>< ol> <li>Name : <s:property value="#paramTag.name" /></li> <li>Age : <s:property value="#paramTag.age" /></li> <li>Status : <s:property value="#paramTag.status" /></li> <li>Birthday : <s:property value="#paramTag.birthday" /></li></ ol></ body></ html> |
The index.jsp file is as follows- This file only contains the hiperlink only.
|
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><! DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"> <%@ taglib prefix="s" uri="/struts-tags"%>< html>< head>< meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Example of Param Tag</title> </head> <body> <a href="ParamTag.action">Example of param Tag</a> </body> </html> |
The Struts mapping file Struts.xml is as follows-
|
<? xml version="1.0" encoding="UTF-8"?><! DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">< struts><constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="false" /> <constant name="struts.custom.i18n.resources" value="ApplicationResources" /><package name="default" namespace="/" extends="struts-default"> <action name="ParamTag" class="roseindia.ParamTag"> <result name="success">/ParamTag.jsp</result> </action> </package></struts> |
The action class ParamTag.java is as follows.
|
package roseindia;import com.opensymphony.xwork2.ActionSupport;public class ParamTag extends ActionSupport { private String name; private String age; private String status; private String birthday; public String execute() throws Exception { return SUCCESS;} public String getName() { return name;} public void setName(String name) { this.name = name;} public String getAge() { return age;} public void setAge(String age) { this.age = age;} public String getStatus() { return status;} public void setStatus(String status) { this.status = status;} public String getBirthday() { return birthday;} public void setBirthday(String birthday) { this.birthday = birthday;} } |
This Program produces output on the basis of the Param tag evaluation, This give the output as-
Output:-

