大家好,我在 jsp 中发现了 js 文件的问题,我有一个警告
<script src="<c:url value="bower_components/jquery/dist/jquery.min.js"/>"></script>
<script src="<c:url value="bower_components/bootstrap/dist/js/bootstrap.min.js"/>"></script>
<script src="<c:url value="bower_components/metisMenu/dist/metisMenu.min.js"/>"></script>
<script src="<c:url value="dist/js/sb-admin-2.js"/>"></script>
我的jsp无法访问js文件
<mvc:resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/views directory -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<mvc:annotation-driven />
警告:org.springframework.web.servlet.PageNotFound - 在名称为“appServlet”的 DispatcherServlet 中未找到带有 URI [/bap/bower_components/jquery/dist/jquery.min.js] 的 HTTP 请求的映射
谁能告诉我问题出在哪里吗,谢谢
最佳答案
First of all let us understand
<mvc:resources mapping="/resources/**" location="/resources/" />
.
您在此处配置 DispatcherServlet
spring MVC 映射所有HTTP
具有模式 /resources/**
的请求到物理目录/resources/
。这样做是为了放置像 cs
这样的资源, js
或images
进入此文件夹webapp/resources
并作为网络应用程序的静态内容。
引用:Spring MVC - include JS or CSS files in a JSP page
现在,您可以通过多种方式解决您的问题,其中之一解释如下:
- 创建一个名为
resources
的目录里面WebContent
。将所有静态内容移动到其各自的目录中,例如移动jquery.min.js
至WebContent/resources/bower_components/jquery/dist/jquery.min.js
对于其他人也是如此。 - 追加
/resources/
到网址。在 JSP 页面中,通过 访问静态内容
<script src="<c:url value="/resources/bower_components/jquery/dist/jquery.min.js"/>"></script>
希望这对您有所帮助,请随时发表评论以获得进一步的帮助!
关于javascript - js没有找到spring mvc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33905592/