cooltoad
cooltoad

Reputation: 171

unable to get external css working in a dynamic web project spring

Am currently working on a spring mvc project on Eclipse. Am unable to get an external css working in a .jsp . My folder structure is as follows

Myproj, WebContent, WEB-INF, css, .css files

I use the following piece of code to reference the css file.

<link href="<c:url value="/css/filename.css" />" rel="stylesheet" type="text/css" />

I use spring jars version 3.1.0. I have also added the following lines of code within myproj-servlet.xml

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

Still am unable to access my css file or get it apply to my jsp file. While using firebug i see that the css link gets a 404 not found only. Where could be the issue/ how can i resolve?

Upvotes: 0

Views: 1121

Answers (1)

Dangling Piyush
Dangling Piyush

Reputation: 3676

Change your resource location to

<mvc:resources location="/WEB-INF/css/" mapping="/css/**"/> 

and while accessing on jsp you could very well write

<c:set var="context" value="${pageContext.request.contextPath}" />

<link rel="stylesheet" type="text/css" href="${context}/css/style.css" />

Cheers.

Upvotes: 1

Related Questions