I've encoutered some problems with using tomcat.For some reason tomcat can't load my stylesheet.The link is defined inside the head.jsp,this file i include using the include directive in all my jsps that need the stylesheet.I found out that this problem occurs when i dispatch from Servlet to Jsp using the request.getRequestDispatcher(...).When i accessed the same file directly,the stylesheet loads normally.
Image1:
Image2:
Image3:
Image4:
You are missing context path of project.
Case 1: Consider your current URL is http://localhost:8585/project_name/
Then including stylesheet with` ``href = "css/style.css"```
==> http://localhost:8585/project_name/css/style.css
Case 2: Consider your current URL is http://localhost:8585/project_name/users
Then including stylesheet with` ``href = "css/style.css"```
==> http://localhost:8585/project_name/users/css/style.css
404 error
So use context path as prefix, To use context path while including javascript or stylesheet use JSTL tag library and url tag to achieve it as given below.
Include JSTL
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
Include stylesheet or scripts by using jstl url tag as given below
<link rel="stylesheet" href="/css/style.css" />" >
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.