Spring MVC External JS无法正常工作

时间:2016-01-08 08:24:03

标签: javascript jquery html spring-mvc

我在JSP文件中有以下主题部分,

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>DDF Generator</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

        <!-- JQuery -->

        <spring:url value="/RESOURCES/JQuery/jquery-1.11.3.min.js"
var="jqueryJs" />
        <script src="${jqueryJs}"/>

        <!-- Bootstrap files -->
        <spring:url
value="/RESOURCES/Bootstrap/bootstrap-3.3.6-dist/js/bootstrap.js"
var="bootstrapJs" />
        <spring:url
value="/RESOURCES/Bootstrap/bootstrap-3.3.6-dist/js/bootstrap.min.js"
var="bootstrapMinJs" />
        <spring:url value="/RESOURCES/Bootstrap/bootstrap-3.3.6-dist/js/npm.js"
var="npmJs" />
        <script src="${bootstrapJs}"/>
        <script src="${bootstrapMinJs}"/>
        <script src="${npmJs}"/>

        <spring:url
value="/RESOURCES/Bootstrap/bootstrap-3.3.6-dist/css/bootstrap-theme.css"
var="bootstrapTheme" />
        <spring:url
value="/RESOURCES/Bootstrap/bootstrap-3.3.6-dist/css/bootstrap-theme.min.css"
var="bootstrapThemeMin" />
        <spring:url
value="/RESOURCES/Bootstrap/bootstrap-3.3.6-dist/css/bootstrap.css"
var="bootstrap" />
        <spring:url
value="/RESOURCES/Bootstrap/bootstrap-3.3.6-dist/css/bootstrap.min.css"
var="bootstrapMin" />
        <link href="${bootstrapMin}" rel="stylesheet" />

        <!-- Including LOGO Image -->
        <spring:url value="/RESOURCES/IMAGESOURCES/schneider.png" var="logo" />

        <!-- Common CSS file for this project -->
        <spring:url value="/RESOURCES/CSS/common.css" var="common" />
        <link href="${common}" rel="stylesheet" />

        <!-- Page specific javascript -->
        <spring:url value="/RESOURCES/JavaScripts/deviceLevelData.js"
var="thisPageJs" />
        <script src="${thisPageJs}"/>

    </head>

我在加载Jquery JS之后加载了特定于页面的JS,但是外部js中的代码仍无效。当它写在“body”部分内时,相同的代码可以工作。任何想法?

1 个答案:

答案 0 :(得分:1)

试试这个

<script src="url"></script>

而不是

<script src="url"/>

还要将其添加到xml配置中:

<mvc:resources location="/resources/" mapping="/resources/**" />