Jaanus
Jaanus

Reputation: 16541

Spring maven , access CSS/JS files

I have a Spring project:

Resource files are under : src/main/resources/style/.........lots of subfolders

servlet.xml:

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

and my jsp:

<link rel="stylesheet" href="<%=request.getContextPath()%>/resources/style/jquery_ui/css/custom-theme/jquery-ui-1.8.23.custom.css"/>

When I browse to my view, gives this link as location:

http://localhost:8080/webapp/WEB-INF/classes/style/jquery_ui/css/custom-theme/jquery-ui-1.8.23.custom.css

How can I get it to show css file correctly?

Upvotes: 1

Views: 2137

Answers (1)

Beau Grantham
Beau Grantham

Reputation: 3456

The standard Maven layout has web resources located in src/main/webapp/resources. The src/main/resources is more for library and Java resources.

Referencing them in your JSP is easily done with the JSTL core c:url tag. You don't need to worry about context root when using these. For example:

<link rel="stylesheet" href="<c:url value="/resources/style/jquery_ui/css/custom-theme/jquery-ui-1.8.23.custom.css" />" />

The library will automatically prepend the context root to this URL.

Upvotes: 4

Related Questions