我需要查看变量是否以键“ef”开头,例如 ef1、efabc、efanythink...如果是,则显示错误消息,我过去是 php 和 jsp 的混合,当然不正确并且有错误,我没有理解jsp:
<c:if test="${empty channel.getChannelName()}">
<%
if (string_starts_with(${channelName}, 'ef')) { header("location:http://google.com"); }
或者显示这个错误的div
<div class="error"> This Channel url Portected!</div>
最佳答案
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/functions" prefix = "fn" %>
<c:if test='${fn:startsWith(channel.channelName, "ef")}'>
...
</c:if>
<c:if test='${not fn:startsWith(channel.channelName, "ef")}'>
...
</c:if>
或者你可以使用
'<c:choose> <c:when>'
关于java - jsp如果变量以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20507082/