File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding a CSS file to the JSP for my Spring app

 
Ray Clark
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ray Clark
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try commenting out the <mvc:resources line and see what happens
 
Ray Clark
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I did, thank you for your help.

Ray
 
Puneet Hattalli
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My bad <mvc:resources location="/resources/**" mapping="/resources/"/> must have been <mvc:resources location="/resources/" mapping="/resources/**"/>.
I have same configuration as above :


Folder Structure is as in attachment.

As for jsp is concerned it is as follows :

The logs for the application are in the attachment .
Now the servlet URL is as follows .. Since it is '/' allows requests will route through Dispatcher.




The logs suggest that No handler is found for the mapping...
What could be the issue ... is it servlet configuration/folder structure..
Capture.PNG
[Thumbnail for Capture.PNG]
Capture.PNG
[Thumbnail for Capture.PNG]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic