spring 当 url 更改时,mvc 背景图像不工作

spring mvc background image not working when url changes

我正在尝试提供背景信息。当 url 为(在登录页面中)

时图像正确加载
/jobsspectrum/login

通过在个人资料页面中使用

<body background="resources/images/black.jpg">

但是当 url 更改时图像不会加载。例如

/jobsspectrum/user/profile
because there is /user in the url before the page where i am using image in profile page.

错误是

message /jobsspectrum/user/resources/images/black.jpg
description The requested resource is not available.

我的头像在resources/images

下面

当 url 不是 /jobsspectrum/

时,它不会选择资源

我的资源处理 class 是:

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {

    registry.addResourceHandler("/resources/**").addResourceLocations("resources/");
    super.addResourceHandlers(registry);
}

我简单地说图像仅在首页中选取,当用户登录时我的 url 从 /jobsspectrum/ 更改为 /jobsspectrum/user/** 并且未加载资源图像部分正确。

使用绝对路径而不是相对路径。

使用 JSTL:

<body background="<c:url value='/resources/images/black.jpg' />">

或者,没有 JSTL:

<body background="${pageContext.request.contextPath}/resources/images/black.jpg">