0

How is this achieved, I have everything mapped from / to the dispatcher Servlet and the css is in the webapp folder. when clicking on the css link href in the source I get a tomcat error.

Do I need to create a @RequestMapping for css?

2

2 Answers 2

3

Css are served without the need of dispatcher (unless you configure it to serve css). Just put them in some folder in your webapp dir and reference them as /YourAppContext/path-to-your-css in your pages.

For example in typical (non-maven) webapp it's inside WebContent/css

Assuming your app's context name is MyApp and you want to reference WebContent/css/main.css you should put something like this in jsp:

<c:url value="/css/main.css" />

or uglier using

/MyApp/css/main.css 

as your css url

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this got me on the right track. I just needed to add <mvc:resources mapping="/csscontent/**" location="/csscontent/" />
0

CSS are client files, not server files. All client files (CSS, Javascript, etc.) have nothing to do with Spring MVC, which acts on servlets (on the server). SO you add your CSS exactly the same way you would if you weren't using Spring MVC.

2 Comments

They come from the server, though, and because of the OP's mapping, are currently being processed by Spring (poorly). The server will act on whatever requests are given to it to handle, regardless of mimetype.
True, what I meant is that the "logic" contained in them have nothing to do with the servlets, and will be "processed" at runtime by the browser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.