Home Struts Struts Struts2.2.1 Tags Struts2.2.1 property Tag Example

Ask Questions?

View Latest Questions


 
 

Struts2.2.1 property Tag Example
Posted on: January 7, 2011 at 12:00 AM
Advertisement
In this Discussion,We will discuss about property tag of struts2.2.1.

Struts2.2.1 property Tag Example

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.

<%@ 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>Property Tag Example</title>

</head>

<body>

First Name:

<s:property value="fname" />

<br>

Last Name:

<s:property value="lname" />

</body>

</html>

The index.jsp file is 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>Property Tag Example</title>

</head>

<body>

<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>

<s:submit value="submit" />

</s:form> 

</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="PropertyTag" class="roseindia.PropertyTag">

<result name="success">/PropertyTag.jsp</result>

</action>

</package>

</struts>

The action class PropertyTag.java is as follows.

package roseindia;

import com.opensymphony.xwork2.ActionSupport;

public class PropertyTag extends ActionSupport {

private String fname;

private String lname;

public String execute() throws Exception {

return SUCCESS;

}

public String getFname() {

return fname;

}

public void setFname(String fname) {

this.fname = fname;

}

public String getLname() {

return lname;

}

public void setLname(String lname) {

this.lname = lname;

}

}

This Program produces output on the basis of the PropertyTag  evaluation, This  give the output as-

Output:-

Download Select Source Code


Related Tags for Struts2.2.1 property Tag Example:


DMCA.com