它工作正常,直到我尝试使用-6ren">
gpt4 book ai didi

java - JSTL:在自定义标签中使用 scriptlet

转载 作者:行者123 更新时间:2023-11-29 05:43:16 25 4
gpt4 key购买 nike

我使用自定义标签来创建某种母版页(模板)。构造如下:

// Template
<%@ tag description="master" pageEncoding="UTF-8"%>
<%@ attribute name="js" fragment="true" %>
<!doctype html>
<html>
<head>
<jsp:invoke fragment="js" />
</head>
<body>
</html>

// Page
<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>
<t:master>
<jsp:attribute name="js">
<script type="text/javascript" src="<spring:url value="/javascript/administration/customers.js" />"></script>
</jsp:attribute>
</t:master>

它工作正常,直到我尝试使用通用解决方案通过在 js 文件名末尾添加随机字符串来禁用 javascript 的浏览器端缓存:

<script type="text/javascript" src="<spring:url value="/javascript/administration/customers.js" />?<%= new java.util.Date().getTime() %>"></script>

它失败了

Scripting elements ( <%!, <jsp:declaration, <%=, <jsp:expression, <%, <jsp:scriptlet ) are disallowed here.

异常

我该如何实现这样的解决方案?谢谢

最佳答案

一个疯狂的建议:-)

使用usebean 在请求范围内生成一个新的Date 对象。然后,每个请求都会导致创建一个新的 Date 对象。这将在整个请求中重复使用。

 <jsp:useBean id="uniqueDate" class="java.util.Date" scope="request"/>  

然后在日期对象上调用 getTime() 方法(如评论中所建议)。

${uniqueDate.time}

关于java - JSTL:在自定义标签中使用 scriptlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16778376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com