Reputation: 1128
I want to load CSS on the JSP page. But I am getting empty pageContext.request.contextPath in JSP page. I am using this approach because if I move the page around in different directories within the templates or JSP then I should not need to keep on making changes to paths of referred CSS or js files.
Jsp page is as below
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix = "x" uri = "http://java.sun.com/jsp/jstl/xml" %>
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix = "fn" uri = "http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@page isELIgnored="false"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Home Page</title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/default-theme.css" />
</head>
<body>
<div class="container">
<H2>Reached Home.</H2>
</div>
</body>
</html>
application.properties file is as below
spring.mvc.view.prefix=/templates/jsp/
spring.mvc.view.suffix=.jsp
I am using Spring version 2.6.0. Along with the following dependencies in pom.xml- spring-boot-starter-web spring-boot-starter-tomcat (scope: provided) tomcat-embed-jasper (scope: provided) jstl
As per Spring Boot, pageContext is Implicit. Then what could be going wrong here? Any help or suggestions would be appriciated.
Upvotes: 1
Views: 997
Reputation: 51
check if remove <%@page isELIgnored="false"%> if not work test : request.getContextPath()
after all see this link : pageContext.request.contextPath not working
Upvotes: 0