Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Struts Struts2 Struts2controltags Set Tag (Data Tag) Example

Related Tutorials


 
 

Share on Google+Share on Google+

Set Tag (Data Tag) Example

Advertisement
In this section, we are going to describe the Set tag . The set tag is a generic tag that is used to assign a value to a variable in a specified scope.

Set Tag (Data Tag) Example

     

In this section, we are going to describe the Set tag. The set tag is a generic tag that is used to assign a value to a variable in a specified scope. It is useful when you wish to assign a variable to a complex expression and then simply reference that variable each time rather than the complex expression. 

Add the following code snippet into the struts.xml file.

struts.xml

<action name="setTag">
   <result>/pages/genericTags/setTag.jsp</result>
</action>

Now create a jsp page using <s:set> tag as  shown in the setTag.jsp page. The set tag is used to assign a value to a variable in a specified scope. The parameters name and value in the tag <s:set name="technologyName" value="%{'Java'}"/> acts as the name-value pair. Here we set the parameters as name="technologyName" value="Java".

setTag.jsp

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

<html>
  <head>
  <title>Set Tag (Data TagExample!</title>
  </head>
  <body>
  <h1><span style="background-color: #FFFFcc">Set Tag 
   (
Data TagsExample!</span></h1>
  <s:set name="technologyName" value="%{'Java'}"/>
  Technology Name: <s:property value="#technologyName"/>
  </body>
</html>

Output of the setTag.jsp:

     

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 20, 2007

Related Tutorials

Discuss: Set Tag (Data Tag) Example   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
as
September 5, 2012
ss

dangers
DMCA.com