Reputation: 2091
I want to create resources folder and load assets from this folder inside jsp files. What I did was adding the following lines to 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
.
And in the jsp file:
<link href="/resources/css/main.css" rel="stylesheet">
But it doesn't load css files. Trying to access .css file from the URL gives me 404 error:
http://localhost:8084/resources/css/main.css/
How can I solve this?
Upvotes: 1
Views: 113
Reputation: 2127
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:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
Upvotes: 1