I downloaded Bootstrap to bind it to JSP pages, JSP pages are in the webapp/jsp directory, CSS lies in webapp/css , the page stubbornly refuses to see the CSS file, although the logic is correct:

 <link rel="stylesheet" href="../css/bootstrap.min.css"> 
  • maybe somewhere the default path is configured separately? - Alexey Fedorov

1 answer 1

First, put all static resources in one place - the resource or static directory. Secondly, it is not necessary, but it is desirable to explicitly indicate in web.xml that the contents of this directory are processed by the default servlet:

 <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>/static/*</url-pattern> </servlet-mapping> 

Thirdly, in the jsp file itself, it is better to use an absolute path:

 <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head> ... <c:set var="staticRoot" value="${pageContext.request.contextPath}/static"/> <link type="text/css" rel="stylesheet" href="${staticRoot}/css/style.css" /> <script type="text/javascript" src="${staticRoot}/js/script.js"></script> </head> <body> ... </body> </html> 

Finally, it is even easier and better to connect bootstrap from CDN:

 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
  • Thank you. Use 3 option - Alexey Fedorov