The property tag is a generic tag that is used to get the property of a value,
which will default to the top of the stack if none is specified.Let's see how to display the following details using
the property tag.
The following Example will shows how to implement the property Tag in the Struts2.2.1 --
First we create a JSP file named PropertyTag.jsp as follows.ADS_TO_REPLACE_1
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE
html PUBLIC
"-//W3C//DTD HTML 4.01
Transitional//EN" <%@taglib prefix="s" uri="/struts-tags"%> <html> <head>ADS_TO_REPLACE_3 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Property Tag Example</title> </head>ADS_TO_REPLACE_4 <body> First Name: <s:property value="fname" />ADS_TO_REPLACE_5 <br> Last Name: <s:property value="lname" />ADS_TO_REPLACE_6 </body> </html> |
The index.jsp file is as follows-
<%@ page language="java" contentType="text/html; charset=UTF-8"ADS_TO_REPLACE_7 pageEncoding="UTF-8"%> <!DOCTYPE
html PUBLIC
"-//W3C//DTD HTML 4.01
Transitional//EN" <%@taglib prefix="s" uri="/struts-tags"%>ADS_TO_REPLACE_8 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">ADS_TO_REPLACE_9 <title>Property Tag Example</title> </head> <body>ADS_TO_REPLACE_10 <s:form action="PropertyTag.action" method="post"> <s:textfield name="fname" key="First Name"></s:textfield> <s:textfield name="lname" key="Last Name"></s:textfield>ADS_TO_REPLACE_11 <s:submit value="submit" /> </s:form> </body>ADS_TO_REPLACE_12 </html> |
The Struts mapping file Struts.xml is as follows-
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLICADS_TO_REPLACE_13 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts>ADS_TO_REPLACE_14 <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="false" />ADS_TO_REPLACE_15 <constant name="struts.custom.i18n.resources" value="ApplicationResources" /> <package name="default" namespace="/" extends="struts-default">ADS_TO_REPLACE_16 <action name="PropertyTag" class="roseindia.PropertyTag"> <result name="success">/PropertyTag.jsp</result> </action>ADS_TO_REPLACE_17 </package> </struts> |
The action class PropertyTag.java is as follows.
package roseindia;ADS_TO_REPLACE_18 import com.opensymphony.xwork2.ActionSupport; public class PropertyTag extends ActionSupport { private String fname;ADS_TO_REPLACE_19 private String lname; public String execute() throws Exception { return SUCCESS;ADS_TO_REPLACE_20 } public String getFname() { return fname;ADS_TO_REPLACE_21 } public void setFname(String fname) { this.fname = fname;ADS_TO_REPLACE_22 } public String getLname() { return lname;ADS_TO_REPLACE_23 } public void setLname(String lname) { this.lname = lname;ADS_TO_REPLACE_24 } } |
This Program produces output on the basis of the PropertyTag evaluation, This give the output as-
Output:-ADS_TO_REPLACE_25
Download Select Source CodeADS_TO_REPLACE_26
Advertisements
Ads
Ads