spring - 在 Spring MVC 中将 js/css 导入到 jsp
问题描述
我有一个 Spring MVC 项目,我可以将 css/js 导入我的 index.jsp 但不能用于其他视图。我试过 ${pageContext.request.contextPath} 但它没有用。
我有这个结构。
小服务程序
resources mapping="/resources/**" location="/resources/theme1/"
意见/*.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 - GET http://localhost:8080/ProyectTest/resources/js/messages.css net::ERR_ABORTED 404
解决方案
我想我解决了你的问题
<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">
推荐阅读
- jenkins - Jenkins 实例在 Centos 上出现离线
- python-3.x - Python正则表达式在日志文件中查找异常
- laravel - Laravel 5.5 - MethodNotAllowedHttpException
- javascript - axios调用的无限循环,React
- java - 通过 https 给定 IP 地址的 Spring Boot 白名单
- gmail - GMAIL RESTful API 是否支持发送非 ASCII 电子邮件地址?
- c++ - CJson - 在字符串周围插入缺少的引号
- snakemake - snakemake 输出中的 lambda 函数
- javascript - 在严格模式的打字稿项目中使用 jsbi
- ruby - 返回方法 local_variables 作为哈希