代码之家  ›  专栏  ›  技术社区  ›  Denis Bazhenov

JSP EL+jQuery“$.ajax()”问题

  •  1
  • Denis Bazhenov  · 技术社区  · 15 年前

    我有简单的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
    

    $.ajax({...}); 字符串是JSP EL表达式(无论在字符串之间放置什么字符) $ { { 没关系,但是我的IDE认为这段代码是坏的JS代码。

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

    1 回复  |  直到 15 年前
        1
  •  1
  •   BalusC    15 年前

    这看起来确实像servletcontainer(或webapplication)使用的EL实现中的一个bug。您需要确定它正在使用哪一个,然后尝试升级/替换它。

    如果升级/替换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.
        });
    });
    
    推荐文章