Struts - <logic:match> <logic:notMatch>例

Struts – の例

この例をダウンロード–Struts-Logic-Match-NotMatch-Example.zip

Struts タグは、指定されたプロパティにsubstringとして指定された値が含まれていることを確認するために使用されます。 たとえば、プロパティ結果が「Google Search Engine」の場合、値「gle」は一致しますが、値「ABC」は一致しません。 条件が一致すると、タグの本文が実行されます。 Struts は反対の方法を実行しています。

Strutsのmatchタグには、「location」という名前の必須属性があり、値は「start」または「end」のいずれかです。

  1. location = “start” –指定された値が指定されたプロパティの開始部分文字列として表示される場合にのみ一致します。 E.g “Google Search Engine” – “Goog” will match, “gine” will not match.

  2. location = “end” –指定された値が指定されたプロパティの終了部分文字列として表示される場合にのみ一致します。 E.g “Google Search Engine” – “Goog” will not match, “gine” will match.

  3. No location define –指定された値が指定されたプロパティの部分文字列として表示される場合に一致します。 E.g “Google Search Engine” – “Goog” will match, “gine” will match.

以下は、およびの使用を示す例です。

LogicExampleAction.java

package com.example.common.action;

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 LogicExampleAction extends Action{

    public ActionForward execute(ActionMapping mapping,ActionForm form,
        HttpServletRequest request,HttpServletResponse response)
        throws Exception {

        request.setAttribute("email", "[email protected]");

        return mapping.findForward("success");
    }

}

LogicExample.jsp

Struts -  & 

Email - [email protected]



1. Is "yong" is a substring of the email? -

    true


    false






2. Is "yongABC" is a substring of the email? -

    true


    false






3. Is email start with "example"? -

    true


    false






4.. Is email start with "yong"? -

    true


    false






5. Is email end with "com"? -

    true


    false






6. Is email end with "net"? -

    true


    false

struts-config.xml




  

     

        

    

  

結果

Struts-logic-match-notmatch-example

Struts -  & 
Email - [email protected]

1. Is "yong" is a substring of the email? - true

2. Is "yongABC" is a substring of the email? - false

3. Is email start with "example"? - true

4.. Is email start with "yong"? - false

5. Is email end with "com"? - true

6. Is email end with "net"? - false