jsp if variable starts with

4.9k views Asked by At

I need view if variable starts with keys "ef", like ef1, efabc, efanythink... and if yes, show error message, i past here mix of php and jsp, of course incorrect and with errors, i no understand jsp:

<c:if test="${empty channel.getChannelName()}">
<%
if (string_starts_with(${channelName}, 'ef')) { header("location:http://google.com"); }

or show this div of error

<div class="error"> This Channel url Portected!</div>

Original file: http://pastebin.com/ach8PXY9

3

There are 3 answers

0
ug_ On

Theres a JSTL method for that!

<c:choose>
    <c:when test="${fn:startsWith(channel.getChannelName(), "ef")}">
        <script type="text/javascript">window.location.replace("http://google.com/");</script></c:when>
    <c:otherwise>
        <div class="error"> This Channel url Portected!</div>
    </c:otherwise>
</c:choose>

http://docs.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/fn/tld-summary.html

0
LHA On
<%@ 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>

OR you can use

'<c:choose> <c:when>'
0
snzro On

also possible:

if (channelName != null && channelName.indexOf("ef") == 0) {
    %><div class="error"> This Channel url Portected!</div><%
}