この例をダウンロードする –

Struts-Logic-Match-NotMatch-Example.zip

Struts <logic:match>タグは、指定されたプロパティが

substring

であることを確認するために使用されます。たとえば、プロパティ結果「Google検索エンジン」、値「gle」は一致し、値「ABC」は一致しません。条件が一致すると、タグの本体が実行されます。 Struts <logic:notMatch>は逆の動作をしています。

Strutsのmatchタグには、 ”

location

“という名前の必須属性があり、値は ”

start

“または ”

end


  1. location = “start”

    – 指定された値が

指定されたプロパティの部分文字列を開始します。たとえば、「Google検索エンジン」 – 「Goog」が一致し、「gine」が一致しません。


  1. location = “end”

    – 指定された値が

指定されたプロパティの終了部分文字列。たとえば、「Google検索エンジン」 – 「Goog」が一致しない場合は、「gine」が一致します。


  1. 場所が定義されていない

    – 指定された値が

指定されたプロパティの部分文字列たとえば、「Google検索エンジン」 – 「Goog」が一致し、「gine」が一致します。

ここでは、<logic:match>

package com.mkyong.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 - <logic:match> & <logic:notMatch>

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 "mkyong"? -

    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 **

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://jakarta.apache.org/struts/dtds/struts-config__1__3.dtd">

<struts-config>
  <action-mappings>

     <action
        path="/LogicTest"
        type="com.mkyong.common.action.LogicExampleAction">

        <forward name="success" path="/pages/LogicExample.jsp"/>

    </action>

  </action-mappings>
</struts-config>

結果


Struts-logic-match-notmatch-example、title = "Struts-logic-match-notmatch-example"

Struts - <logic:match> & <logic:notMatch>
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 "mkyong"? - true

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

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

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