gpt4 book ai didi

java - JSP EL + jQuery "$.ajax()"问题

转载 作者:太空宇宙 更新时间:2023-11-04 08:49:37 24 4
gpt4 key购买 nike

我有简单的 JSP:

<jsp:directive.attribute name="severity" type="java.lang.String" required="true"/>
<jsp:directive.attribute name="currentSeverity" type="java.lang.String" required="true"/>

<c:if test="${severity ne currentSeverity}">
<c:url value="/session" var="url">
<c:param name="severity" value="${severity}"/>
</c:url>
<li><a href="#" onclick="$.ajax({
type: 'GET',
url: '${url}',
success: function() {
window.location.reload();
}
});"><c:out value="${severity}"/></a></li>
</c:if>

但是当我评估它时,servlet 引擎会抛出:

org.apache.jasper.JasperException:
/WEB-INF/tags/severity-position.tagx(17,9) PWC6287:
The attribute prefix success does not correspond to any imported tag library

不知何故,JSP引擎认为$.ajax({...});字符串是JSP EL表达式(无论${之间放置什么字符)。当我反斜杠 {$ 时一切正常,但随后我的 IDE 认为这段代码是损坏的 JS 代码。

那么,为什么JSP引擎认为$.ajax({...})是JSP EL表达式呢?

最佳答案

这看起来确实像是相关 servlet 容器(或 Web 应用程序)使用的 EL 实现中的错误。您需要弄清楚它正在使用哪一个并尝试升级/替换它。

如果升级/替换 EL 实现没有帮助,那么我强烈建议将整个脚本移至其自己的函数中 .js使用 <script> 加载的文件在 HTML <head> 中元素。这也是正常做法。更重要的是,我会给链接一个类名,以便您可以在 $(document).ready() 期间挂载它。并添加 click()因此。例如

<a href="${url}" class="someName">

$(document).ready(function() {
$('.someName').click(function() {
$.ajax({
type: 'GET',
url: $(this).attr('href'), // This sets the actual value of ${url}.
success: function() {
window.location.reload();
}
});
return false; // Blocks link from executing the default href action.
});
});

关于java - JSP EL + jQuery "$.ajax()"问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3644790/

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