首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Spring MVC和Bootstrap - css,img工作.js不工作

Spring MVC和Bootstrap - css,img工作.js不工作
EN

Stack Overflow用户
提问于 2013-01-30 21:06:33
回答 1查看 1.9K关注 0票数 1

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

下面是Dispatcher servlet:

代码语言:javascript
运行
复制
<?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部分

代码语言:javascript
运行
复制
<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>

我需要知道我做错了什么

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-30 23:03:00

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

代码语言:javascript
运行
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14604770

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档