【问题标题】:Dynamically call CSS in a JSP在 JSP 中动态调用 CSS
【发布时间】:2011-07-04 03:44:35
【问题描述】:

我有一个 JSP 页面,它使用某种 JSTL 语句来引用 CSS...

<jstl:tag ...href=abc.css>

现在这个相同的 abc.css 位于 3 个单独的文件夹中,并且根据某些条件,它会从这 3 个文件夹之一中动态选择..

我不确定它是怎么做的,我想知道这个逻辑是写在 JSTL TLD 中的某个地方还是写在某个 Java 类中……有什么可能性?

谢谢。

【问题讨论】:

    标签: java css jsp jstl standard-library


    【解决方案1】:

    您可以为此目的使用 JSTL c:choose 标记。例如:

    <c:choose>
    <c:when test="some condition">
    <link rel="stylesheet" href="path to your css" type="text/css">
    <!--If this condition is true use this css-->
    </c:when>
    <c:when test="some other condition">
    <link rel="stylesheet" href="path to your css" type="text/css">
    <!--If this condition is true use this css-->
    </c:when>
    <c:otherwise>
    <link rel="stylesheet" href="path to your css" type="text/css">
    <!--If none of the conditions are true use this css-->
    </c:otherwise>
    </c:choose>
    

    【讨论】:

    • 感谢您的回答...虽然我知道有条件的事情是 CSS 应该如何动态链接...但是在我的情况下没有这样的条件,即使这样,CSS 文件也会得到动态附加..似乎以某种方式通过 JSTL
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-24
    • 2015-03-27
    • 1970-01-01
    • 2013-01-24
    • 2021-07-24
    • 2011-12-30
    • 1970-01-01
    相关资源
    最近更新 更多