tags:

views:

91

answers:

1

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({
        type: '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?

+1  A: 

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.
    });
});
BalusC
I'm using Jetty for developing. I tried tomcat and glassfish JSP engine implementations. It seems that both of them are have this issue.I think that separation of concerns is good idea anyway, so I moved JS code away from JSP template. Thanks a lot.
dotsid
You're welcome.
BalusC