Struts– 例

下载此示例– 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”将不匹配。
  2. location =“ end” –仅在给定值显示为给定属性的结尾子字符串时匹配。 例如,“ Google搜索引擎” –“ Goog”将不匹配,“ gine”将匹配。
  3. 没有位置定义 –如果给定值显示为给定属性的子字符串,则匹配。 例如,“ Google搜索引擎” –“ Goog”将匹配,“ gine”将匹配。

这是显示<logic:match>和<logic:notMatch>用法的示例。

LogicExampleAction.java

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", "mkyong123456@yahoo.com");
		
		return mapping.findForward("success");
	}
 
}

LogicExample.jsp









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

Email - mkyong123456@yahoo.com

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>

结果

http:// localhost:8080 / StrutsExample / LogicTest.do

Struts-logic-match-notmatch-example
Struts - <logic:match> & <logic:notMatch>
Email - mkyong123456@yahoo.com

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

翻译自: https://mkyong.com/struts/struts-logicmatch-logicnotmatch-example/

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值