I put index.jsp inside WEB-INF. Then I have a servlet which dispatch request to that file.
@WebServlet(name="Home", urlPatterns={"/"})
public class Home extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.getRequestDispatcher("/WEB-INF/index.jsp").forward(request, response);
}
}
I have a css folder which is outside the WEB-INF folder. It contains the css.css file.
The This is the content of index.jsp file:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" href="<c:url value="/css/css.css" />" rel="stylesheet">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
The content of css file:
body {
color: red;
}
Question: Why doesn't the sentence "Hello World" turn red? Why can't the index.jsp file access the css file?