开发者

JSP EL + jQuery "$.ajax()" problem

I have simple 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({
        t开发者_Go百科ype: 'GET',
        url: '${url}',
        success: function() {
            window.location.reload();
        }
    });"><c:out value="${severity}"/></a></li>
</c:if>

But when I'm evaluate it servlet engine throws:

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

Somehow JSP engine thinks that $.ajax({...}); string is JSP EL expression (no matter what characters are placed between $ and {). When I backslash { or $ it's all ok, but then my IDE thinks that this code is broken JS code.

So, why JSP engine thinks that $.ajax({...}) is JSP EL expression?


This look indeed like a bug in the EL implementation used by the servletcontainer (or webapplication) in question. You need to figure which one it is using and try upgrading/replacing it.

If upgrading/replacing the EL implementation doesn't help, then I'd warmly recommend do move that whole script out into an function in its own .js file which you load using <script> in the HTML <head> element. That's also the normal practice. Even more, I'd give the link a classname so that you can just hook on it during $(document).ready() and add the click() accordingly. E.g.

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

with

$(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.
    });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜