【问题标题】:Js not found spring mvcjs找不到spring mvc
【发布时间】:2023-03-05 01:08:01
【问题描述】:

大家好,我在 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 请求的映射

谁能告诉我是什么问题,谢谢

【问题讨论】:

  • 你的结构是什么样的。如果您将 url /resources/** 映射到 /resources,那么它应该在资源下。例如:">

标签: javascript java spring jsp spring-mvc


【解决方案1】:

首先让我们了解&lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;

这里你正在配置 spring MVC 的 DispatcherServlet 以将所有具有模式 /resources/**HTTP 请求映射到物理目录 /resources/。这样做是为了将csjsimages 等资源放入此文件夹webapp/resources 并作为Web 应用程序的静态内容。 参考:Spring MVC - include JS or CSS files in a JSP page

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

  • WebContent 内创建一个名为resources 的目录。将所有静态内容移动到其各自目录中,例如将jquery.min.js 移至WebContent/resources/bower_components/jquery/dist/jquery.min.js,其他人也同样如此。
  • /resources/ 附加到网址。在 JSP 页面中,以
  • 的身份访问静态内容

&lt;script src="&lt;c:url value="/resources/bower_components/jquery/dist/jquery.min.js"/&gt;"&gt;&lt;/script&gt;

希望对你有帮助,欢迎留言寻求帮助!

【讨论】:

  • 我找到了我刚刚添加的解决方案 ">谢谢大家
猜你喜欢
  • 2015-01-15
  • 2015-03-31
  • 2018-07-06
  • 2016-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-06
  • 2013-04-12
相关资源
最近更新 更多