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

Struts - exemple

Téléchargez cet exemple -Struts-Logic-Match-NotMatch-Example.zip

La balise Struts est utilisée pour vérifier que la propriété donnée contient la valeur donnée en tant quesubstring. Par exemple, un résultat de propriété "Google Search Engine", la valeur "gle" correspondra, tandis que la valeur "ABC" ne correspondra pas. Si la condition est vérifiée, le corps de la balise sera exécuté. Le Struts fait le contraire.

La balise de correspondance de Struts a un attribut incontournable nommé «location», avec la valeur «start» ou «end»

  1. location = “start” - Correspond uniquement si la valeur donnée apparaît comme sous-chaîne de départ de la propriété donnée. E.g “Google Search Engine” – “Goog” will match, “gine” will not match.

  2. location = “end” - Correspond uniquement si la valeur donnée apparaît comme sous-chaîne de fin de la propriété donnée. E.g “Google Search Engine” – “Goog” will not match, “gine” will match.

  3. No location define - Correspond si la valeur donnée apparaît comme sous-chaîne de la propriété donnée. E.g “Google Search Engine” – “Goog” will match, “gine” will match.

Voici l'exemple pour montrer l'utilisation des et .

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




  

     

        

    

  

Résultat

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