Struts —— Logic 标签

<%
 request.setAttribute("uname","sMLDN") ;

 // 通过标签判断在指定范围中是否有属性存在
  %>
  <logic:equal name="uname" scope="request" value="MLDN">
 <h1>语句满足条件,内容是${uname}</h1>
  </logic:equal>
  <logic:notEqual name="uname" scope="request" value="MLDN">
 <h1>语句不满足条件,内容不是${uname}</h1>
  </logic:notEqual>

 

 

 

<%
 // request.setAttribute("ref",new Integer(1)) ;
 request.setAttribute("ref",new Character('1')) ;
 // 通过标签判断在指定范围中是否有属性存在
  %>
  <logic:equal name="ref" scope="request" value="1">
 <h1>内容为1!!!</h1>
  </logic:equal>
  <logic:notEqual name="ref" scope="request" value="1">
 <h1>内容不为1!!!</h1>
  </logic:notEqual>
  <logic:greaterThan name="ref" scope="request" value="0">
 <h1>内容大于0!!!</h1>
  </logic:greaterThan>
  <logic:greaterEqual name="ref" scope="request" value="1">
 <h1>内容大于等于1!!!</h1>
  </logic:greaterEqual>
  <logic:lessThan name="ref" scope="request" value="2">
 <h1>内容小于2!!!</h1>
  </logic:lessThan>
  <logic:lessEqual name="ref" scope="request" value="1">
 <h1>内容小于等于1!!!</h1>
  </logic:lessEqual>

 

 

 

 

<%
  // List 是Collection的子类 如果是  set它将自动排序
  List all = new ArrayList() ;
  all.add("mldn") ;
  all.add("LiXingHua") ;
  all.add("www.MLDN.cn") ;
  // 将对象保存在属性之中
  request.setAttribute("list",all) ;
 %>
 <logic:iterate id="str" name="list" scope="request">
  <h2>${str}</h2>
 </logic:iterate>

 

 

 

<%
  /*
   要通过迭代标签输出Map集合
   回顾:Map集合本身不直接支持迭代输出
   输出步骤:
    Map --> Set --> Iterator --> Map.Entry --> key、value
  */
  Map m = new HashMap() ;
  m.put("name","LiXingHua") ;
  m.put("url","www.MLDN.cn") ;
  // 将对象保存在属性之中
  request.setAttribute("list",m) ;
 %>
 <logic:iterate id="str" name="list" scope="request">
  <h2>${str.key} --> ${str.value}</h2>
 </logic:iterate>

 

 

 

 

<%
  /*
   在Map中保存多个Collection集合,该如何进行输出呢?
  */
  List all = null ;
  Map m = new HashMap() ;

  all = new ArrayList() ;
  all.add("魔乐先生") ;
  all.add("李兴华") ;
  m.put("name",all) ;

  all = new ArrayList() ;
  all.add("mole") ;
  all.add("www.MLDN.cn") ;
  m.put("info",all) ;
  // 在一个map中保存了多个集合,每个集合又包含多个内容

  request.setAttribute("list",m) ;

 %>
 <logic:iterate id="str" name="list" scope="request">
  <h2>${str.key} --> <br>
   <logic:iterate id="tempstr" name="str" scope="page" property="value">
    <li>${tempstr}
   </logic:iterate>
  </h2>
 </logic:iterate>

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值