Struts的logic标签(转)

来源:互联网 发布:淘宝线上客服招聘 编辑:程序博客网 时间:2024/05/17 22:04
(1)empty标签
类名:org.apache.struts.taglib.logic.EmptyTag
标签体:bodycontent=JSP
引用logic:empty
属性 attribute:name,property,scope
功能:判断对象的值是否为空
(2)equal
类名:org.apache.struts.taglib.logic.EqualTag
标签体:bodycontent=JSP
引用logic:equal
属性 attribute:cookie,header,name,parameter,property,scope,value
功能:等于比较符

(3) forward
org.apache.struts.taglib.logic.ForwardTag
标签体:bodycontent=empty
引用logic:forward
属性 attribute:name
功能:页面导向,查找配置文件的全局forward

(4) greaterEqual
类名:org.apache.struts.taglib.logic.GreaterEqualTag
标签体:bodycontent=JSP
引用logic:greaterEqual
属性 attribute:cookie,header,name,parameter,property,scope,value
功能:大于等于比较符

(5)greaterThan
类名:org.apache.struts.taglib.logic.GreaterThanTag
标签体:bodycontent=JSP
引用logic:greaterThan
属性 attribute:cookie,header,name,parameter,property,scope,value
功能:大于比较符

(6) iterator
类名:org.apache.struts.taglib.logic.IterateTag
标签体:bodycontent=JSP
引用logic:iterator
属性 attribute:collection,id,indexId,length,name,offset,property,scope,type
功能:显示列表为collection的值(List ,ArrayList,HashMap等)

(7)lessEqual
类名org.apache.struts.taglib.logic.LessEqualTag
标签体:bodycontent=JSP
logic:lessEqual
属性 attribute:cookie,header,name,parameter,property,scope,value
功能:小于等于比较符

(8)lessThan
类名:org.apache.struts.taglib.logic.LessThanTag
标签体:bodycontent=JSP
logic:lessThan
属性 attribute:cookie,header,name,parameter,property,scope,value
功能:小于比较符

(9)match
类名:org.apache.struts.taglib.logic.MatchTag
标签体:bodycontent=JSP
引用logic:match
属性 attribute:cookie,header,location,name,parameter,property,scope,value
功能:比较对象

(10)messagesNotPresent
类名:org.apache.struts.taglib.logic.MessagesNotPresentTag
标签:bodycontent=JSP
引用logic:messagesNotPresent
属性 attribute:name,property,message
功能:ActionMessages/ActionErrors对象是否不存在

(11)messagePresent
类名:org.apache.struts.taglib.logic.MessagesPresentTag
标签:bodycontent=JSP
引用logic:messagePresent
属性 attribute:name,property,message
功能:ActionMessages/ActionErrors对象是否不存在

(12)notEmpty
类名:org.apache.struts.taglib.logic.NotEmptyTag
标签:bodycontent=JSP
引用logic:notEmpty
属性 attribute:name,property,scope
功能:比较对象是否不为空

(13)notEqual
类名:org.apache.struts.taglib.logic.NotEqualTag
标签:bodycontent=JSP
引用logic:notEqual
属性 attribute:cookie,header,name,parameter,property,scope,value

(14)notMatch
类名:org.apache.struts.taglib.logic.NotMatchTag
标签:bodycontent=JSP
引用logic:notMatch
属性 attribute:cookie,header,location,name,parameter,property,scope,value
功能:比较对象是否不相等

(15)notPresent
类名:org.apache.struts.taglib.logic.NotPresentTag
标签:bodycontent=JSP
引用logic:notPresent
属性 attribute:cookie,header,name,parameter,property,role,scope,user
功能:request对象传递参数是否不存在

(16)present
类名:org.apache.struts.taglib.logic.PresentTag
标签:bodycontent=JSP
引用logic:present
属性 attribute:cookie,header,name,parameter,property,role,scope,user
功能:request对象传递参数是否存在

(17)redirect
类名:org.apache.struts.taglib.logic.RedirectTag
标签:bodycontent=JSP
引用logic:redirect
属性 attribute:anchor,forward,href,name,page,paramId,paramName,paramProperty,paramScope,property,scope,transaction
功能;页面转向,可传递参数

例子:

1、... 
parameter要进行比较的HTTP请求参数的名称
name如果要进行比较的是bean或bean的属性,则这个属性代表bean的名称
property要进行比较的bean属性的名称

logic使用
  使用struts中的标记,可以完成一些复杂的循环。
  下面用了一个小例子说明这一点:
  
  IterateBean.java:
  
  package beantest;
  
  import org.apache.struts.action.ActionForm;
  
  public class IterateBean extends ActionForm {
  private String[] name_coll = null;
  public void setName_coll(String[] name_coll) {
  this.name_coll = name_coll;
  }
  public String[] getName_coll() {
  return this.name_coll;
  }
  
  private String[] name_new = null;
  public void setName_new(String[] name_new) {
  System.out.println("IterateBean:setName_new(String[])");
  this.name_new = name_new;
  }
  public String[] getName_new() {
  return this.name_new;
  }
  }
  
  IterateAction.java
  
  package beantest;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.apache.struts.action.Action;
  import org.apache.struts.action.ActionForm;
  import org.apache.struts.action.ActionForward;
  import org.apache.struts.action.ActionMapping;
  
  public class IterateAction extends Action {
  public ActionForward execute(
  ActionMapping mapping,
  ActionForm form,
  HttpServletRequest request,
  HttpServletResponse response) throws Exception {
  IterateBean ibean = (IterateBean) form;
  String[] temp = {"bitan", "helen"};
  ibean.setName_coll(temp);
  temp = new String[] {"aaaaa", "bbbbb"};
  ibean.setName_new(temp);
  return mapping.findForward("iterate-view");
  }
  }
  
  iterate-view.jsp:
  
  
  
  
  
  
  
  
  name: ; code:

  

  
  ★〓〓〓〓〓〓〓〓★

  
  

  

  
  lower.jsp:
  
  hello, iterate!
  
  struts-config.xml:
  
  
     "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
  "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
  
  web.xml:
  action
  org.apache.struts.action.ActionServlet
  
   config
   /WEB-INF/struts-config.xml
  
  1
  action
  /eye/*
  输出效果:
  
  name: bitan ; code: aaaaa
  name: bitan ; code: bbbbb
  ★〓〓〓〓〓〓〓〓★
  hello, iterate!
  name: helen ; code: aaaaa
  name: helen ; code: bbbbb
  ★〓〓〓〓〓〓〓〓★
  hello, iterate!
  
  如上所示,一个循环中不能直接将多个变量同时输出;但在循环中嵌套循环可以实现一种复杂效果。
  
  要实现在一个循环中将多个变量同时输出,可以引用标记。