简体   繁体   English

资产在4.1.7春季不加载

[英]Assets don't load in spring 4.1.7

I want to create resources folder and load assets from this folder inside jsp files. 我想创建资源文件夹并从jsp文件中的此文件夹加载资产。 What I did was adding the following lines to main-servlet.xml: 我所做的是在main-servlet.xml中添加了以下几行:

<mvc:annotation-driven />
<mvc:resources mapping="/resources/css/**" location="/resources/css/" />

Placing resources/css , resources/js , resources/images folders on the same level as WEB-INF and META-INF . resources/cssresources/jsresources/images文件夹放置在与WEB-INFMETA-INF相同的级别上。

And in the jsp file: 并在jsp文件中:

<link href="/resources/css/main.css" rel="stylesheet">

But it doesn't load css files. 但是,它不会加载CSS文件。 Trying to access .css file from the URL gives me 404 error: 尝试从URL访问.css文件会给我404错误:

http://localhost:8084/resources/css/main.css/

How can I solve this? 我该如何解决?

Change config to: 将配置更改为:

<mvc:resources mapping="/resources/**" location="/resources/" />

And try this: 尝试一下:

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

Don't forget include taglib at the top of your jsp file: 不要忘记在jsp文件的顶部包含taglib:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM