【问题标题】:Import js/css to jsp in Spring MVC在 Spring MVC 中将 js/css 导入到 jsp
【发布时间】:2019-10-30 04:58:15
【问题描述】:

我有一个 Spring MVC 项目,我可以将 css/js 导入我的 index.jsp,但不能导入其他视图。 我试过 ${pageContext.request.contextPath} 但没有用。

我有这个结构。

Servlet

resources mapping="/resources/**" location="/resources/theme1/"

views/*.jsp

 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ page session="false" %>
<html>
<head>
    <title>Message Page</title>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>

 <script src="<c:url value="/resources/css/messages.js" />"></script>
<link href="<c:url value="/resources/js/messages.css" />" rel="stylesheet">
</head>

在浏览器日志中我得到:

GET http://localhost:8080/ProyectTest/resources/css/messages.js net::ERR_ABORTED 404 – 获取http://localhost:8080/ProyectTest/resources/js/messages.cssnet::ERR_ABORTED 404

【问题讨论】:

标签: spring spring-mvc


【解决方案1】:

我想我已经解决了你的问题

<link href="<c:url value="/resources/js/messages.css" />" rel="stylesheet">

仔细看。您的 css 文件位于 css 文件夹内,但您声明了 js 文件夹的路径。 我认为使用这条线对你有用。

<link href="<c:url value="/resources/css/messages.css" />" rel="stylesheet">

【讨论】:

  • @Alberto。呵呵。没关系。它发生了!
猜你喜欢
  • 2013-07-16
  • 1970-01-01
  • 2016-12-19
  • 1970-01-01
  • 2014-12-04
  • 2016-11-08
  • 1970-01-01
  • 2016-04-29
  • 1970-01-01
相关资源
最近更新 更多