本文介绍了无法加载资源:服务器在Spring MVC中以404(未找到)状态响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将css文件加载到jsp中,它没有加载并显示消息无法加载资源:服务器响应状态为404(未找到).以下是我的代码
I am trying to load the css file into jsp, it is not loading and showing the message Failed to load resource: the server responded with a status of 404 (Not Found).the following is my code
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Bootstrap Form With Spring Mvc Example</title>
<link href="<c:url value='/resources/css/bootstrap.css'/>" rel="stylesheet" media="screen">
</head>
在配置类中,我添加了以下代码:
in configuration class I have added the below code:
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations("/resources/");
}
我已经尝试了所有解决方案,但没有发现问题所在,有人可以帮助我吗?
I have tried all the solutions, I did not find what's the wrong,can any one help me?
推荐答案
以这种方式尝试:
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/css/**")
.addResourceLocations("/css/");
}
这假设您的目录结构为:
This assumes your directory structure is:
src
main
java
resources
css
webapp
重点是您没有在资源处理程序中指定资源级别.
The point is that you don't specify the resources level in your resource handler.
这篇关于无法加载资源:服务器在Spring MVC中以404(未找到)状态响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!