简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM