struts logic标签

 

Logic标签介绍:

Acompare标签

<% 

        request.setAttribute("intBean",new Integer(100));

%>

<logic:equal name="intBean" value="100" >

        The value of intBean is "100".<p> 

</logic:equal >

intBean的值是100则显示执行标签体

<% 

        SomeBean bean=new SomeBean();

        bean.setName("Linda");

        request.setAttribute("someBean",bean);

%>

<logic:notEqual name="someBean" property="name" value="Tom" >

        The name of someBean is not "Tom" <p>

</logic:notEqual >

someBean(javabean)的属性name值是Tom则显示标签体

<logic:greaterThan parameter="arg1" value="100" >

        The first request parameter is greater than 100 <p>

</logic:greaterThan >

在URL请求参数中,参数名为arg1的值为100,则显示标签体。

Bmatch标签

<%

  request.setAttribute("authorName", "LindaSun");

%>

<logic:match name="authorName" scope="request" value="Linda">

   <bean:write name="authorName"/> has the string 'Sun' in it.

</logic:match>

request范围内,名为authorName对应的值若跟Linda匹配则执行方法体

<logic:match name="authorName" scope="request" value="Linda" location="start">

   <bean:write name="authorName"/> starts with the string 'Linda'.

</logic:match>

比上面的标签多了一个从哪里匹配的说明

Cforward 标签

<logic:forward name="index"/>

需要在struts-config.xml文件中配置

<global-forwards>

    <name="index" path="/index.jsp"/>

</global-forwards>

Dredirect标签

<logic:redirect href="http://www.apache.org"/>

重定向到其他应用

Epresence 标签

<% request.setAttribute("emptyString", ""); %>

<logic:empty name="emptyString">

   The variable named emptyString is empty!<P>

</logic:empty>

名字为emptyString对应的值为" ",则显示标签体

<logic:present name="noSuchBean" property="noSuchProperty">

   Both noSuchBean and noSuchProperty exist!

</logic:present>

存在名字为noSuchBean,并且它存在属性noSuchProperty。则显示标签体

<% 

ActionErrors errors = new ActionErrors();

errors.add("totallylost", new ActionMessage("application.totally.lost"));

request.setAttribute("myerrors", errors);

%>

<logic:messagesPresent name="myerrors">

   Yes, there are errors in myerrors collection.

</logic:messagesPresent>

存在名字为myerrorsActionErrors,则显示标签体

<logic:messagesPresent property="totallylost">

   There is an error named "totallylost".

</logic:messagesPresent>

存在名字为totallylostActionMessage,则显示标签体

Flogic标签

<%

HashMap months = new HashMap();

months.put("Jan.", "January");

months.put("Feb.", "February");

months.put("Mar.", "March");

request.setAttribute("months", months);

%>

<logic:iterate id="element" indexId="ind" name="months">

  <bean:write name="ind"/>. 

  <bean:write name="element" property="key"/>:

  <bean:write name="element" property="value"/><BR>

</logic:iterate><P>

迭代输出map中的数据,格式为:索引.键:值

<%

HashMap h = new HashMap();

String vegetables[] = {"pepper", "cucumber"};

String fruits[] = {"apple","orange","banana","cherry","watermelon"};

String flowers[] = {"chrysanthemum","rose"};

String trees[]={"willow"};

h.put("Vegetables", vegetables);

h.put("Fruits", fruits);

h.put("Flowers", flowers);

h.put("Trees",trees);

request.setAttribute("catalog", h);

%>

<logic:iterate id="element" indexId="ind" name="catalog">

  <bean:write name="ind"/>. <bean:write name="element" property="key"/><BR>

  <logic:iterate id="elementValue" name="element" property="value" length="3" offset="1">

      -----<bean:write name="elementValue"/><BR>

  </logic:iterate>

</logic:iterate><P>

双层迭代:

格式为: 索引.

         -------值 (每个键对应的值,从下标1开始,一共输出3个)

<%

 Vector animals=new Vector();

 animals.addElement("Dog");

 animals.addElement("Cat");

 animals.addElement("Bird");

 animals.addElement("Chick");

 request.setAttribute("Animals", animals);

%>

<logic:iterate id="element" name="Animals">

   <bean:write name="element"/><BR>

</logic:iterate><p>

迭代输出集合中的元素

<logic:iterate id="element" indexId="index" name="Animals" offset="1" length="2">

   <bean:write name="index"/>.<bean:write name="element"/><BR>

</logic:iterate><p>

迭代输出结合,格式为: 索引.集合中的元素

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值