javascript - js没有找到spring mvc

标签 javascript java spring jsp spring-mvc

大家好,我在 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 这样的资源, jsimages进入此文件夹webapp/resources并作为网络应用程序的静态内容。 引用:Spring MVC - include JS or CSS files in a JSP page

现在,您可以通过多种方式解决您的问题,其中之一解释如下:

  • 创建一个名为 resources 的目录里面WebContent 。将所有静态内容移动到其各自的目录中,例如移动jquery.min.jsWebContent/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/

相关文章:

javascript - 如何在node.js中获取带有参数的HTTP请求?

java - 防止Spring的RestTemplate为multipart/form-data中的每个参数添加 header

spring - 微服务之间的原子操作

javascript - BCE0051 : Operator '*' cannot be used with a left hand side of type 'float' and a right hand side of type 'Object'

javascript - 如何通过chrome扩展检测按钮事件

java - 如何使用Jena TDB存储本地版本的Linked Movie Database

Java JAI - 从许多较小的图像创建 1 个大的 jpg 图像

java - Spring @CacheEvict 使用通配符

java - Spring - 在运行时注册作用域bean

javascript - 使用 if 语句调用函数