Java 用于测试的JSTL表达式(如果不是)
我正在尝试使用JSTL条件来确定某些文本是否以表达式“服务包含”开头。然而,我发现这个表达式是不正确的,并且有一些错误。你能确定这有什么问题吗 下面是JSP页面的一部分Java 用于测试的JSTL表达式(如果不是),java,regex,jsp,jstl,taglib,Java,Regex,Jsp,Jstl,Taglib,我正在尝试使用JSTL条件来确定某些文本是否以表达式“服务包含”开头。然而,我发现这个表达式是不正确的,并且有一些错误。你能确定这有什么问题吗 下面是JSP页面的一部分 <%-- Attributes: ruleView RuleViewDto ruleView --%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <c:set var="ruleDesc" va
<%--
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>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
表达式${!fn:startsWith(ruleDesc,'Service include')}
有什么问题?应该怎样
某些文本是否不包含表达式“服务包括…”
如果不包含,则可以使用返回-1的indexOf
${fn:indexOf(ruleDesc, 'Service include')==-1}
您也可以尝试忽略案例
${fn:indexOf(ruleDesc.toLowerCase(), 'service include')==-1}
编辑
请使用以下示例代码再次测试:
<c:set var="ruleDesc" value="abc Service include abc" />
Not starts with: ${!fn:startsWith(ruleDesc, 'Service include')}
不是以${!fn:startsWith(ruleDesc,'Service include')开头
表达式${!fn:startsWith(ruleDesc,'Service include')}
表达式本身看起来不错,JSP中没有指定的一件事是用于fn
名称空间的标记库。在JSP页面的开头添加这个taglib
定义
<%--
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>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
错误#1:MSG
JasperException:应为相等的符号
错误#2:MSG
jaspereException:java.lang.ClassNotFound异常:
错误#3:MSG
ELException:未能分析表达式+
JasperException:包含无效的表达式:
错误#4:MSG
JasperException:需要引号符号
错误#5:MSG
jaspereException:java.lang.ClassNotFound异常:
错误#6:MSG
JasperException:end标记“startWith
也可以正常工作,但只有当文本出现在字符串的开头时,它才能正常工作@Braj,我想知道ruleDesc是否以“服务包含”开头@Gimby,我想比较txt2中存在txt1。好吧,我想这是我的错,我不够具体。我的意思是你用“不是”。+1来回答。不幸的是,我想知道文本是否以“服务包含”开头:)你能告诉我的表达式有什么问题吗?我有个问题我已经为startsWith()
进行了测试,并且在我这边工作得很好,正如我已经提到的,这就是我分享另一种方法的原因。