jQuery in Action, 2nd edition*
The moose likes Spring and the fly likes Adding a CSS file to the JSP for my Spring app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Adding a CSS file to the JSP for my Spring app" Watch "Adding a CSS file to the JSP for my Spring app" New topic
Author

Adding a CSS file to the JSP for my Spring app

Ray Clark
Ranch Hand

Joined: Aug 16, 2012
Posts: 55
I'm not using Spring theme's, I just want to add a CSS file to the JSP and I think I have the URI reference wrong. The file is in the WEB-INF/resources/css directory.

Dispatcher Servlet:


The JSP has:


The file exists and is named correctly but the CSS isn't being applied when it is in the external file. Any ideas?

Thanks,
Ray

Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1680
    
    7

Get it out of the WEB-INF directory.

looking at your resources mapping you might have a structure like this:



You can look at this blog post by Gordon Dickens for an alternative directory structure.
http://gordondickens.com/wordpress/2012/07/03/enterprise-spring-best-practices-part-1-project-config/

with his setup you would have a styles directory. Either will work though.


[How To Ask Questions][Read before you PM me]
Ray Clark
Ranch Hand

Joined: Aug 16, 2012
Posts: 55
Thank you, I got it to work now.

Per your suggestion I moved the resources directory to the same level as the WEB-INF directory and changed the JSP to be the following:



Just to make sure that I understand. Since the web.xml file has the servlet mapping for the Dispatcher Servlet as /, then the Dispatcher Servlet really is serving up this resource right?

The reason that I ask is because this resolves to "/application context/resources/css/dvdTrackerCSS.css" in the jsp.

Thanks,
Ray
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1680
    
    7

Try commenting out the <mvc:resources line and see what happens
Ray Clark
Ranch Hand

Joined: Aug 16, 2012
Posts: 55
Thank you Bill, when I comment out the line


then it can't serve up the resources. The error is:



It looks like that line is required for the Dispatcher Servlet to be able to serve up the static content.

Ray
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1680
    
    7

then the Dispatcher Servlet really is serving up this resource right?

It looks like that line is required for the Dispatcher Servlet to be able to serve up the static content.


Yup. Sounds like you figured out the answer to your question By mapping it to / you are essentially saying that the dispatcher servlet is the default servlet and it will be handling all requests including those for static content.
Ray Clark
Ranch Hand

Joined: Aug 16, 2012
Posts: 55
Yes I did, thank you for your help.

Ray
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding a CSS file to the JSP for my Spring app