Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将变量从jsp文件传递到标记_Java_Jsp_Spring Mvc_Jsp Tags - Fatal编程技术网

Java 将变量从jsp文件传递到标记

Java 将变量从jsp文件传递到标记,java,jsp,spring-mvc,jsp-tags,Java,Jsp,Spring Mvc,Jsp Tags,我正在使用标签将我的应用程序主体插入到应用程序的全局布局中。我正在尝试将.jsp文件中声明的新css/js文件(特定于应用程序)插入到标记中(不确定我是否清楚,但代码应该澄清这一点) 这是我的wrapper.tag文件(稍微简化): 书名 下面是一个使用该标记的jsp文件示例: <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib prefix="t" tagdir="/WEB-INF/tags"

我正在使用标签将我的应用程序主体插入到应用程序的全局布局中。我正在尝试将.jsp文件中声明的新css/js文件(特定于应用程序)插入到标记中(不确定我是否清楚,但代码应该澄清这一点)

这是我的wrapper.tag文件(稍微简化):


书名
下面是一个使用该标记的jsp文件示例:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="t" tagdir="/WEB-INF/tags" %>

<t:wrapper>
    <div class="container">
        <form class="form-signin">
            <h2 class="form-signin-heading">Please sign in</h2>
            <label for="inputEmail" class="sr-only">Email address</label>
            <input type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>

            <label for="inputPassword" class="sr-only">Password</label>
            <input type="password" id="inputPassword" class="form-control" placeholder="Password" required>

            <div class="checkbox">
                <label>
                    <input type="checkbox" value="remember-me"> Remember me
                </label>
            </div>

            <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
        </form>
    </div>
</t:wrapper>

请登录
电子邮件地址
密码
记得我吗
登录

我想在jsp文件中声明变量,以插入新的css/js文件以加载到包装标签的
中。

我找到了一种方法,下面是实现方法

只需在jsp文件中的标记调用中传递一个属性:

<spring:url value="/resources/user/css/login.css" var="loginCss" />

<t:wrapper css="${loginCss}">

并在包装标签的
中添加:

<%@ attribute name="css" %>
<c:if test="${!empty css}" >
    <link href="${css}" rel="stylesheet" />
</c:if>

JS也是如此

<%@ attribute name="css" %>
<c:if test="${!empty css}" >
    <link href="${css}" rel="stylesheet" />
</c:if>