簡體   English   中英

使用多個選項檢查JSP條件的最佳實踐

[英]Best practice to check a JSP conditional with multiple options

如果字符串等於可能性列表,我需要檢查JSP。 解決方案應該應用於JSP(不能訪問Java代碼),我避免使用scriptlet,但說實話,我很想使用它。 目前代碼如下所示:

<c:choose>
    <c:when test="${name eq 'Edgar' or
        name eq 'Mike' or
        name eq 'Tijuana' or
        name eq 'Mozell' or
        name eq 'Dominga' or
        name eq 'Genie' or
        name eq 'Lacey' or
        name eq 'Eliza' or
        name eq 'Dona' or
        name eq 'Leigh' or
        name eq 'Manda' or
        name eq 'Amelia' or
        name eq 'Bob'}">
            <%-- Stuff --%>
    </c:when> 
    <c:otherwise> 
        <%-- other stuff --%>
    </c:otherwise>
</c:choose>

這個解決方案有效但很難看到你的意見。 你會如何改進它?

謝謝!

我會優先使用這樣的東西:

<% if (PredefinedNameSet.contains(name)) { %> 
    jsp-stuff 
<% } else { %> 
    other jsp-stuff 
<% } %>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM