struts2 标签初识 Data Tags

来源:互联网 发布:政用大数据宣传片 编辑:程序博客网 时间:2024/05/13 09:58

1、url

<-- Example 1 -->
<s:url value="editGadget.action">
    <s:param name="id" value="%{selected}" />
</s:url>

<-- Example 2 -->
<s:url action="editGadget">
    <s:param name="id" value="%{selected}" />
</s:url>

<-- Example 3-->
<s:url includeParams="get">
    <s:param name="id" value="%{'22'}" />
</s:url>

2、a

<s:url id="testUrlId" namespace="/example" action="Login">
</s:url>
<s:a href="%{testUrlId}">
111</s:a>

 

  1. <s:url id="next" value="fenye.action">   
  2.       <s:param name="param1" >${Action属性}</s:param>   
  3.      <s:param name="param2">常值</s:param>   
  4. </s:url>   
  5. <s:a href="%{next}">链接</s:a>  

<s:url id="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>

http://zhiweiv.javaeye.com/blog/361478
3、action

使用action标签 可以允许在JSP页面中直接调用Action,因为需要调用Action,故可以指定需要被调用Action的name以及namespace。如果指定 了executeResult参数的属性值为true,该标签还会把Action的处理结果(视图支援)包含到本页面中来。
action标签的属性:
id: 可选属性,该属性将会作为该Action的引用ID
name: 必填属性,指定该标签调用哪个Action
namespace: 可选,指定该标签调用的Action所在的namespace.
executeResult: 可选,指定是否要将Action的处理结果页面包含到本页面。默认是false,即不包含
ignoreContextParams: 可选,它指定该页面中的请求参数是否需要传入调用的Action、默认是false,即将本页的请求参数传入被调用的Action。

struts.xml

        <action name="Login_*" method="{1}" class="example.Login">
            <result name="input">/example/Login.jsp</result>
           <!-- <result type="redirectAction">Menu</result>  -->
  <result name="success">/fileupload/index.jsp</result>
        </action>

do.jsp

<li>
Execute the action's result, render the page here.
<s:action namespace="/example" name="Login" executeResult="true"/>
</li>

 

<div>The following action tag will not execute result, but put a String in request scope
     under an id "stringByAction" which will be retrieved using property tag</div>
<s:action name="actionTagAction!default" executeResult="false" />
<s:property value="#attr.stringByAction" />
4、bean

<-- in jsp form -->
<s:bean name="example.Login" var="p">
  <s:param name="username" value="'BAR'" />
 The value of foot is : <s:property value="username"/>, when inside the bean tag <br />
</s:bean>
 The value of foot is : <s:property value="#p.username"/>, when inside the bean tag <br />

  1. name: 必填,指定要实例化的JavaBean的实现类
  2. var: 可选。如指定了该属性,则该Javabean实例会被放入StackContext中(不是ValueStack),从而允许直接通过该var属性来访问该JavaBean实例。该var可以用id来代替,但推荐使用var属性!

5、date

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

<html>
 <head>
  <title>Date Tag Example</title>
 </head>
 <body>
  <h2>Current Date Format</h2>
   <table border="1" width="35%">
    <tr>
     <td><b>Date Format</b></td>
     <td><b>Date</b></td>
    </tr>
    <tr>
     <td>Day/Month/Year</td>
     <td><s:date name="currentDate" format="dd/MM/yyyy" /></td>
    </tr>
    <tr>
     <td>Month/Day/Year</td>
     <td><s:date name="currentDate" format="MM/dd/yyyy" /></td>
    </tr>
    <tr>
     <td>Month/Day/Year</td>
     <td><s:date name="currentDate" format="MM/dd/yy" /></td>
    </tr>
    <tr>
     <td>Month/Day/Year Hour<B>:</B>Minute</td>
     <td><s:date name="currentDate" format="MM/dd/yy hh:mm" /></td>
    </tr>
    <tr>
     <td>Month/Day/Year Hour<B>:</B>Minute<B>:</B>Second</td>
     <td><s:date name="currentDate" format="MM/dd/yy hh:mm:ss" /></td>
    </tr>
    <tr>
     <td>Nice Date (Current Date & Time)</td>
     <td><s:date name="currentDate" nice="false" /></td>
    </tr>
    <tr>
     <td>Nice Date</td>
     <td><s:date name="currentDate" nice="true" /></td>
    </tr>
   </table>
   
 </body>
</html>

  1. format:  属性 , 指定 属性 , 将根据 属性指定的各市来格式化日期 .   
  2. nice:  属性 , 只能 ture 或者 false. 它用于指定是否 出指定日期和当前 刻之 , false, .   
  3. name: 必填属性 , 指定格式化的日期   
  4. var 属性 , 指定 元素的  

6、debug

<s:debug/>

debug 标签 主要用于 测试 ,它在 面上生成一个超 接,通 过该链 接可以 ValueStack Stack Context 中的所有 信息

7、i18n

载资 源包到 。它可以允 text 访问 任何 源包的信息,而不只当前 action 关联 源包。

Value 必填属性 源包的 路径

 例如:在WEB-INF/class/test的目录下建立一abc.propertise文件,文件内容

delete=删除

save=保存

这样就可以使用i18n标签

<s:i18n name="test.abc">

<s:text name="save"/>

<s:text name="delete"/>

</s:i18n>

8、include

<-- One: -->
<s:include value="myJsp.jsp" />
9、param

给bean传值的函数

<s:bean name="com.mkyong.common.Person" var="personBean">
 <s:param name="nickName">ah pig ah dog</s:param>
 <s:param name="age">99</s:param>
 <s:param name="favorFruit" value="#fruitBean"></s:param>
</s:bean>

10、property

<s:bean name="example.Login" var="p">
  <s:param name="username" value="'BAR'" />
 The value of foot is : <s:property value="username"/>, when inside the bean tag <br />
</s:bean>
<s:push value="p">
    <!-- Example 1: -->
    <s:property value="username" />
    <!-- Example 2: -->TextUtils
    <s:property value="username" default="a default value" />
</s:push>

 11、push

<s:bean name="example.Login" var="p">
  <s:param name="password" value="'BAR'" />
   The value of foot is : <s:property value="password"/>, when inside the bean tag <br />
   </s:bean>
<s:push value="p">                            
<s:bean name="example.Login" var="s">
 <s:param name="password" value="'password'" />
  <s:param name="username" value="top.password" />
   The value of foot is : <s:property value="username"/>, when inside the bean tag <br />
   </s:bean>
 </s:push>

 

<h4>1. Normal way</h4>

First name : <s:property value="#p.username" /><br/>

<h4>2. Push way</h4>
<s:push value="#p" >
First name : <s:property value="username" /><br/>
</s:push>

12、set

<s:set var="varUrl" value="%{'http://www.mkyong.com'}" />
<s:property value="varUrl" />
<s:set var="varUrl" value="%{#p.username}" />
<s:property value="varUrl" />

 

13、text

用于国际化读取资源文件结合i18n使用