Ecplise(jsp文件)导入css文件路径没错,但是没有样式(不生效/无效)

一、检查css文件的【路径】是否正确

1、:将页面在【浏览器】打开,按【Ctrl+u】,查看【页面源代码】(也可右键点击)

若页面进行【跳转】------>说明css路径没错
在这里插入图片描述

二、若路径有问题

参考链接:
1、Jsp中引入css等外部文件路径问题
https://blog.csdn.net/prospective0821/article/details/79775626?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-11&spm=1001.2101.3001.4242
2、用eclipse写web项目中jsp导入图片和css文件的路径问题https://blog.csdn.net/hydhyd0/article/details/72872099
3、Eclipse的WEB项目>HTML/JSP中嵌入CSS样式表(相对路径)https://blog.csdn.net/baofei_dyz/article/details/51191001?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-15&spm=1001.2101.3001.4242
若还没解决自行百度,小白个人能力有限o(╥﹏╥)o~~~

三、因个人的【项目】原因,需设置【过滤器】,页面返回跳转时,所有页面设置加载为【text/html】,引发错误

转载链接:
Resource interpreted as Stylesheet but transferred with MIME type text/html: css失效
https://www.cnblogs.com/StevenZheng/p/10797887.html

1、异常信息:

Resource interpreted as Stylesheet but transferred with MIME type text/html:http://xx/css/input.css
在这里插入图片描述

2、可能原因:

设置【过滤器】或者【某个地方】对所有的资源请求,
【返回页面】设置全部转为了【text/html】

3、检查方式

利用【浏览器】查看【请求头和响应头】
在这里插入图片描述

4、解决方法

在过滤器中设置【返回页面的格式】:

 设置字符集
		req.setCharacterEncoding("UTF-8");
//返回页面设置
		String url = req.getRequestURI();
		System.out.println("url:" + url);
		if (url.indexOf(".css") > 0 || url.indexOf(".js") > 0 || url.indexOf(".png") > 0) {
    
    
			chain.doFilter(req, resp);
			return;
		}
		resp.setContentType("text/html;text/html; charset=UTF-8");

在这里插入图片描述

5、解决效果

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44727274/article/details/111604779