struts2标签

append 和 iterator

参考:http://www.roseindia.net/struts/struts2/struts2controltags/append-tag.shtml

在Action类的execute方法中,实例化List对象

public String execute()throws Exception{ myList = new ArrayList(); myList.add("www.Roseindia.net"); myList.add("Deepak Kumar"); myList.add("Sushil Kumar"); myList.add("Vinod Kumar"); myList.add("Amit Kumar");

myList1 = new ArrayList(); myList1.add("www.javajazzup.com"); myList1.add("Himanshu Raj"); myList1.add("Mr. khan"); myList1.add("John"); myList1.add("Ravi Ranjan"); return SUCCESS; }

jsp页面中使用append和iterator两个tag

<s:append id="myAppendList"> <s:param value="%{myList}" /> <s:param value="%{myList1}" /> </s:append>

<s:iterator value="%{#myAppendList}"> <s:property /><br> </s:iterator>

generator 和 iterator

参考:http://www.roseindia.net/struts/struts2/struts2controltags/generator-tag.shtml

在jsp中使用,'www.Roseindia.net,Deepak Kumar,Sushil Kumar,Vinod Kumar,Amit Kumar'这些内容被分行的显示在页面上。

<s:generator val="%{'www.Roseindia.net,Deepak Kumar,Sushil Kumar,Vinod Kumar,Amit Kumar'}" separator=","> <s:iterator> <s:property /><br/> </s:iterator> </s:generator>

参考:http://www.roseindia.net/struts/struts2/struts2controltags/GeneratorTagCountAttribute.shtml

count="5" -->在jsp页面中显示前5个

<s:generator val="%{'www.Roseindia.net,Deepak Kumar,Sushil Kumar,Vinod Kumar,Amit Kumar, Sanjay, Vijay '}" count="5" separator=","> <s:iterator> <s:property /><br/> </s:iterator> </s:generator> 参考:http://www.roseindia.net/struts/struts2/struts2controltags/GeneratorTagIdAttribute.shtml <s:generator val="%{'www.Roseindia.net,Deepak Kumar,Sushil Kumar,Vinod Kumar,Amit Kumar'}" count="4" separator="," id="myAtt" /> <% Iterator i = (Iterator) pageContext.getAttribute("myAtt"); while(i.hasNext()) { String s = (String) i.next(); %> <%=s%> <br/> <% } %>

iterator

参考:http://www.roseindia.net/struts/struts2/struts2controltags/iterator-tag.shtml

在Action类的execute方法中实例化一个List

public String execute()throws Exception{ myList = new ArrayList(); myList.add("Fruits"); myList.add("Apple"); myList.add("Mango"); myList.add("Orange"); myList.add("Pine Apple"); return SUCCESS; }

在Jsp中可以通过list的名字来调用 <s:iterator value="myList"> <s:property /><br> </s:iterator>

merge

参考:http://www.roseindia.net/struts/struts2/struts2controltags/merge-tag.shtml 在Action类的execute方法中实例化两个List public String execute() throws Exception{ myList = new ArrayList(); myList.add("www.Roseindia.net"); myList.add("Deepak Kumar"); myList.add("Sushil Kumar"); myList.add("Vinod Kumar"); myList.add("Amit Kumar"); myList1 = new ArrayList(); myList1.add("www.javajazzup.com"); myList1.add("Himanshu Raj"); myList1.add("Mr. khan"); myList1.add("John"); myList1.add("Ravi Ranjan"); return SUCCESS; }

在jsp中,用merge tag把两个List合并,在iterator中用merge的id来调用 <s:merge id="mergeId"> <s:param value="%{myList}" /> <s:param value="%{myList1}" />

</s:merge> <s:iterator value="%{#mergeId}"> <s:property /><br> </s:iterator> 显示顺序: Display first element of the first list. Display first element of the second list. Display second element of the first list. Display second element of the second list. Display third element of the first list. Display thrid element of the second list.....and so on.

subset

参考:http://www.roseindia.net/struts/struts2/struts2controltags/subsetTag.shtml public String execute() throws Exception{ myList = new ArrayList(); myList.add(new Integer(50)); myList.add(new Integer(20)); myList.add(new Integer(100)); myList.add(new Integer(85)); myList.add(new Integer(500)); return SUCCESS; }

调用Action类中的List <s:subset source="myList"> <s:iterator> <s:property /><br> </s:iterator> </s:subset> 在页面上显示前三个 <s:subset source="myList" count="3"> <s:iterator> <s:property /><br> </s:iterator> </s:subset> 在页面上显示从2开始的3个 <s:subset source="myList" count="3" start="2"> <s:iterator> <s:property /><br> </s:iterator> </s:subset>

action tag

参考:http://www.roseindia.net/struts/struts2/struts2controltags/action-tag.shtml The action tag is a generic tag that is used to call actions directly from a JSP page by specifying the action name and an optional namespace. The body content of the tag is used to render the results from the Action. Any result processor defined for this action in struts.xml will be ignored, unless the executeResult parameter is specified. 在struts.xml中定义action映射 <action name="actionTag" class="net.roseindia.actionTag"> <result name="success">/pages/genericTags/success.jsp</result> </action> public String execute() throws Exception{ return SUCCESS; }

在jsp页面写入下面代码,那么当请求actionTag.action时,无论Action类net.roseindia.actionTag中怎么处理、如何设定页面转向,此请求直接转到successs.jsp页面 <s:action name="success"> <b><i>The action tag will execute the result and include it in this page.</i></b></div> </s:action>

bean tag

参考:http://www.roseindia.net/struts/struts2/struts2controltags/bean-tag.shtml 定义一个包含name属性的普通JavaBean, public class companyName { private String name; public void setName(String name){ this.name =name ; } public String getName(){ return name; } }

在jsp中调用 <s:bean name="net.roseindia.companyName" id="uid"> <s:param name="name">RoseIndia</s:param> <s:property value="%{name}" /><br> </s:bean>

date tag

参考:http://www.roseindia.net/struts/struts2/struts2controltags/date-tag.shtml private Date currentDate; public String execute() throws Exception{ setCurrentDate(new Date()); return SUCCESS; } <s:date name="currentDate" format="MM/dd/yy" />

<s:date name="currentDate" format="MM/dd/yy hh:mm" />

<s:date name="currentDate" format="MM/dd/yy hh:mm:ss" />

Nice Date (Current Date & Time):<s:date name="currentDate" nice="false" />

Nice Date:<s:date name="currentDate" nice="true" />

include tage

是不是可以替换frame

<body> <h1><span style="background-color: #FFFFcc">Include Tag (Data Tags) Example!</span></h1> <s:include value="myBirthday.jsp" /> </body>

param tag

参考:http://www.roseindia.net/struts/struts2/struts2controltags/param-tag.shtml <ui:component> <ui:param name="empname">Vinod</ui:param><br> <ui:param name="empname">Amit</ui:param><br> <ui:param name="empname">Sushil</ui:param> </ui:component> Case 1. <param name="empname">Amit</param> Here the value would be evaluated to the stack as a java.lang.String object. Case 2. <param name="empname" value="Vinod"/> Here the value would be evaluated to the stack as a java.lang.Object object.

set tag

参考:http://www.roseindia.net/struts/struts2/struts2controltags/set-tag.shtml

set tag给指定范围内的变量赋值,得到name-value值对 赋值:<s:set name="technologyName" value="%{'Java'}"/> 调用:Technology Name: <s:property value="#technologyName"/> 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".

Text Tag

参考:http://www.roseindia.net/struts/struts2/struts2controltags/text-tag.shtml

struts.xml 文件中定义

<action name="textTag" class="net.roseindia.textTag"> <result>/pages/genericTags/textTag.jsp</result> </action>

在textTag.java文件所在包下,创建一个package.properties,内容如下: webname1 = http://www.RoseIndia.net
webname2 = http://www.javajazzup.com
webname3 = http://www.newstrackindia.com

在jsp文件调用,如下,前三行显示package.properties对应信息;第四行显示Vinod, Amit, Sushil, .......;最后一行empname <s:text name="webname1"></s:text><br> <s:text name="webname2"></s:text><br> <s:text name="webname3"></s:text><br> <s:text name="empname">Vinod, Amit, Sushil, .......</s:text><br> <s:text name="empname"></s:text>

property tag

参考:http://www.roseindia.net/struts/struts2/struts2controltags/property-tag.shtml

定义个JavaBean

public class companyName { private String name; public void setName(String name){ this.name =name ; } public String getName(){ return name; } }

第二行给companyName的name属性赋值;第三行显示该值(RoseIndia),相当于调用了getName()方法;, <s:bean name="net.roseindia.companyName" id="uid"> <s:param name="name">RoseIndia</s:param> <s:property value="%{name}" /><br> </s:bean> <!-- Default value --> <s:property value="name" default="Default Value" /> <s:property value="%{name}" /> it prints the result of myBean's getMyBeanProperty() method. <s:property value="name" default="Default Value" /> it prints the result of companyName's getName() method and if it is null, print 'a default value' instead.

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭