1

我将 STS Eclipse 与 Spring Template MVC 项目一起使用。我想使用 Bootstrap,我在 webapp/resources 下创建了 css、js 和 img 目录,并将所有需要的文件放在这些文件夹下。我对 .css 文件没有任何问题,但我无法找到 .js 文件。该应用程序可以正确使用外部 .js 引用。

这是 Dispatcher servlet:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context.xsd">

<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />

<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value=".jsp" />
</beans:bean>

<context:component-scan base-package="org.dani.bootstrap" />



</beans:beans>

这是js脚本的jsp部分

<script type="text/javascript" src="<c:url value="resources/js/bootstrap.js"/>"> </script>
<!-- <script src="<c:url value="/resources/js/bootstrap-dropdown.js"/>"> </script>-->
<script type="text/javascript" src="<c:url value="resources/js/jquery-1.9.0.min.js" />"> </script>
<script type="text/javascript" src="<c:url value="resources/js/jquery-migrate-1.0.0.min.js" />"></script>

我需要知道我做错了什么

4

1 回答 1

0

为了获得更多可见性,您应该将 url 变量和脚本分开。您应该通过添加“/”在您的 URL 中包含完整路径。试试这个:

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

<c:url value="/resources/js/jquery-1.9.0.min.js" var="jqueryUrl"/>
<script src="${jqueryUrl}" type="text/javascript"><!-- required for FF3 and Opera --></script>
于 2013-01-30T15:02:59.937 回答