Including style sheet in a jsp page with Spring MVC?

Files in WEB-INF are not directly public accessible. Only an intermediating (controller) Servlet can access and stream them for you with help of ServletContext#getResourceAsStream() That's exactly what Spring (as any other decent MVC framework) does with JSP files. You can't access JSP files directly by URL.

That would potentially leak source code or break the application behaviour.

Files in /WEB-INF are not directly public accessible. Only an intermediating (controller) Servlet can access and stream them for you with help of ServletContext#getResourceAsStream(). That's exactly what Spring (as any other decent MVC framework) does with JSP files.

You can't access JSP files directly by URL. That would potentially leak source code or break the application behaviour. So you have basically 2 options here: Put CSS files in public webcontent (just move one folder above WEB-INF, so that /css is at same level as /WEB-INF).

Create a Servlet which listens on an url-pattern of /css/*, gets the requested CSS file by HttpServletRequest#getPathInfo() and basically gets an InputStream from it using the aforementioned ServletContext#getResourceAsStream() and writes it to the OutputStream of the response along a correct set of response headers with at least Content-Type and Content-Length. After all I think option 1 is easier and more suitable for your requirement ;).

I figured that had something to do with it. I believe I will go with option 1 for now. Thanks!

– Casey Feb 9 '10 at 20:03 You're welcome. – BalusC Feb 9 '10 at 20:08.

Spring-style implementation of 2nd approach from @BalusC is to using mvc:resources, like that: and after this your main. Css file should be available at /css/main. Css (NOTE: if it does not work, check that DispatcherServlet is mapped to /).

It does not work as-is for me. I have a mapping /app for my DispatcherServlet (otherwise Tiles is not working with /). In that case a reference to my javascript file will be: – ruffp Dec 8 '11 at 17:14 @ruffp Yes, AFAIR, requires to work and thus DispatcherServlet should be mapped to / – php-coder Dec 9 '11 at 2:28.

Or try this " type="text/css"/> it may work.

Casey was asking about using a element to include a stylesheet, so it's not really related to jsp taglibs. – Rob Heiser Jul 14 '11 at 19:15.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions