Struts2学习之路(七)—— Struts2标签

本文详细介绍了如何使用Struts2标签库的标签,包括属性标签、UI标签和Ajax标签的应用实例,以及如何在实际项目中进行整合与实践。

1.如何使用Strut2标签库的标签?

在JSP页面的源码顶部中加入代码

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

2.标签分类及使用:

(1)属性标签

a)控制标签

  • if
  • elseif
  • else
  • append
  • generator
  • iterator
  • merge
  • sort
  • subset

示例代码:

I. if elseif else

 

<s:if test="%{false}">
    <div>Will Not Be Executed</div>
</s:if>
<s:elseif test="%{true}">
    <div>Will Be Executed</div>
</s:elseif>
<s:else>
    <div>Will Not Be Executed</div>
</s:else>

 

II. sort

<!-- 示例1 -->
<s:sort comparator="myComparator" source="myList">
     <s:iterator>
     <!-- do something with each sorted elements -->
     <s:property value="..." />
     </s:iterator>
</s:sort>
 
<!-- 示例2 -->
<s:sort var="mySortedList" comparator="myComparator" source="myList" />
 
<%
   Iterator sortedIterator = (Iterator) pageContext.getAttribute("mySortedList");
   for (Iterator i = sortedIterator; i.hasNext(); ) {
     // do something with each of the sorted elements
   }
%>

b)数据标签

  • a
  • action
  • bean
  • date
  • debug
  • i18n
  • include
  • param
  • property
  • push
  • set
  • text
  • url

示例代码:

I. a

<s:url var="testUrlId" namespace="/subscriber" action="customField" method="delete">
    <s:param name="customFieldDefinition.id" value="${id}"/>
</s:url>
<s:a errorText="Sorry your request had an error." preInvokeJS="confirm('Are you sure you want to delete this item?')" href="%{testUrlId}">
    <img src="<s:url value="/images/delete.gif"/>" border="none"/>
</s:a>
 
<img xsrc="<s:url value="/images/delete.gif"/>" border="none"/><s:a><img xsrc="<s:url value="/images/delete.gif"/>" border="none"/></s:a>

II. bean

<-- in freemarker form -->
[@s.bean name="org.apache.struts2.example.counter.SimpleCounter" var="counter"]
  [s:param name="foo" value="BAR"/]
  The value of foo is : [s:property value="foo"/], when inside the bean tag.<br />
[/s:bean]
 
<-- in jsp form -->
<s:bean name="org.apache.struts2.example.counter.SimpleCounter" var="counter">
  <s:param name="foo" value="BAR" />
  The value of foot is : <s:property value="foo"/>, when inside the bean tag <br />
</s:bean>

III. i18n

<s:i18n name="myCustomBundle">
   The i18n value for key aaa.bbb.ccc in myCustomBundle is <s:property value="text('aaa.bbb.ccc')" />
</s:i18n>

VI. textfield

<s:textfield name="lastName" label="<s:text name="person.lastName"/>" ../>

(2)UI标签

a)表格标签

  • checkbox
  • checkboxlist
  • combobox
  • datetextfield
  • doubleselect
  • head
  • file
  • form
  • hidden
  • inputtransferselect
  • label
  • optiontransferselect
  • optgroup
  • password
  • radio
  • reset
  • select
  • submit
  • textarea
  • textfield
  • token
  • updownselect

b)非表格标签

  • actionerror
  • actionmessage
  • component
  • div
  • fielderror

c)Ajax标签

  • a
  • autocompleter
  • bind
  • datetimepicker
  • div
  • head
  • submit
  • tabbedPanel
  • textarea
  • tree
  • treenode

 

转载于:https://www.cnblogs.com/denisechen/p/4683026.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值