Prashant Chauhan Prashant Chauhan - 2 months ago 12
CSS Question

Unable to link css to JSP page

I am not able to link the css to the JSP page -

Project structure:

webapp
resources
css
bootstrap-iso.css
WEB-INF
views
jsp
app.jsp


The following code in the jsp file works:

<link rel="stylesheet" href="https://formden.com/static/cdn/bootstrap-iso.css"/>


However, it doesn't work when I give either of the following

<link rel="stylesheet" href="../../../resources/css/bootstrap-iso.css"/>
<link rel="stylesheet" href="/resources/css/bootstrap-iso.css"/>


I also have resource handler setup in the ApplicationConfig file

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}

Answer

Try to configure resources with in the spring-web-config.xml file:

<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />

And link the css file with c:url:

<link href="<c:url value="/resources/css/bootstrap-iso.css" />" rel="stylesheet">