开发者

jQuery validation plugin problem when served by JSP using @include

Greetings!

I'm trying to combine several JS files into one and serve it through JSP but I'm running into a problem with the jquery validation plugin 1.6

The JSP aggregating various .js files:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/javascript" pageEncoding="UTF-8"  %>

<c:if test="${jquery}">
    <%@include file="/js/jQuery/jquery-1.4.x.js" %>
</c:if>

<c:if test="${navMenu}">
    <%@include file="/js/verticalNavMenu.js.jsp" %>
</c:if>

<c:if test="${validate}">
    <%@include file="/js/jQuery/jquery.validate.js" %>
</c:if>

I've tested including the jQuery file and the custom verticalNavMenu file and all's fine

Including jquery.validate.js breaks the whole thing.

开发者_C百科

Here's the kicker though, if don't aggregate the validation plugin in the JSP file, but call it in the file that requires it ( form.jsp for example ) all work like a charm.

Any hints will be appreciated.


The code looks fine. As per the comments ("jQuery is not defined"), the only cause for this problem would be that you included the jQuery validation file without including the jQuery core file itself. Thus, when ${validate} evaluates true, you should ensure that ${jquery} also evaluates true. You can also do that in the c:if block:

<c:if test="${jquery || validate}">
    <%@include file="/js/jQuery/jquery-1.4.x.js" %>
</c:if>


so you probably have something in one of those files that causes a syntax error in the JS when something else goes before or after it. You should look at the file and see what that is.

try putting

;

between the files, that might help. I cant help more without seeing the concatted file

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜