Java 用于测试的 JSTL 表达式(如果不是)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24910120/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 15:32:40  来源:igfitidea点击:

JSTL Expression for test if Not

javaregexjspjstltaglib

提问by Umesh Patil

I am trying to know whether certain text starts with an expression "Service include.." using JSTL condition. However, I see that this expression is incorrect and error some. Can you please identify what is wrong with this.

我想知道某些文本是否使用 JSTL 条件以表达式“ Service include..”开头。但是,我看到这个表达式是不正确的,并且错误一些。你能找出这有什么问题吗?

Below is part of JSP page.

下面是 JSP 页面的一部分。

<%--  
    Attributes: ruleView
    RuleViewDto ruleView
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ruleDesc" value="${rule.description}"/>

<c:if test="${!fn:startsWith(ruleDesc, 'Service include')}">        

    <td align="right"  class="imgButton"
        onclick="RuleSet.removeRule('${ruleView.stepId}', '${rule.code}');" style="padding-left: 10px; padding-right: 10px;" 
        ><img src="../img/delete.gif" /></td>
</c:if>

What is wrong with Expression ${!fn:startsWith(ruleDesc, 'Service include')}? How how should it be ?

表达式有什么问题${!fn:startsWith(ruleDesc, 'Service include')}?应该怎样?

采纳答案by Roman C

What is wrong with Expression ${!fn:startsWith(ruleDesc, 'Service include')}

表达式有什么问题 ${!fn:startsWith(ruleDesc, 'Service include')}

the expression itself looks good, one thing you didn't specify in the JSP is a taglib used for fnnamespace. Add this taglibdefinition at beginning of the JSP page.

表达式本身看起来不错,您没有在 JSP 中指定的一件事是用于fn命名空间的 taglib 。taglib在 JSP 页面的开头添加此定义。

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

回答by Braj

whether certain text doesn't containexpression "Service include.."

某些文字是否不contain表达“服务包括..”

You can use indexOfthat return -1 if doesn't contain

indexOf如果不包含,您可以使用该 return -1

${fn:indexOf(ruleDesc, 'Service include')==-1}


You can try ignore case as well

您也可以尝试忽略大小写

${fn:indexOf(ruleDesc.toLowerCase(), 'service include')==-1}


EDIT

编辑

please test it again at your end with below sample code:

请在最后使用以下示例代码再次测试:

<c:set var="ruleDesc" value="abc Service include abc" />
Not starts with: ${!fn:startsWith(ruleDesc, 'Service include')}

回答by J.M.I. MADISON

WRONG#1:<c:if not test="${ some_bool }">MSG</c:if>

错误#1:<c:if not test="${ some_bool }">MSG</c:if>

JasperException: equalsymbol expected

JasperException:预期相等的符号

WRONG#2:<c:if Not test="${ some_bool }">MSG</c:if>

错误#2:<c:if Not test="${ some_bool }">MSG</c:if>

JasperException: java.lang.ClassNotFoundException:

JasperException:java.lang.Class NotFound异常:

WRONG#3:<c:if test="${Not some_bool }">MSG</c:if>

错误#3:<c:if test="${Not some_bool }">MSG</c:if>

ELException: Failed to parse the expression +JasperException: contains invalid expression(s):

ELException:无法解析表达式+JasperException:包含无效表达式:

WRONG#4:<c:if test=not"${ some_bool }">MSG</c:if>

错误#4:<c:if test=not"${ some_bool }">MSG</c:if>

JasperException: quotesymbol expected

JasperException:需要引用符号

WRONG#5:<c:if test=Not"${ some_bool }">MSG</c:if>

错误#5:<c:if test=Not"${ some_bool }">MSG</c:if>

JasperException: java.lang.ClassNotFoundException:

JasperException:java.lang.Class NotFound异常:

WRONG#6:<c:if test="${ ! some_bool }">MSG<c:if/>

错误#6:<c:if test="${ ! some_bool }">MSG<c:if/>

JasperException: The end tag "</c:forEach" is unbalanced

JasperException:结束标记“</c:forEach”不平衡



CORRECT#1:<c:if test="${not some_bool }">MSG</c:if>

正确#1:<c:if test="${not some_bool }">MSG</c:if>

CORRECT#2:<c:if test="${ ! some_bool }">MSG</c:if>

正确#2:<c:if test="${ ! some_bool }">MSG</c:if>