views:

48

answers:

1

I am using Spring MVC, and am using the UrlFilenameViewController to directly map incoming URLs onto my View Resolver without a controller in between. I'm using this to have Freemarker written CSS and JS files, by simply having a .css.ftl and .js.ftl file in the appropriate place. This much all works great.

Some browsers seem to have problems with .css files being returned without a Content-type of text/css, and the Freemarker view resolver doesn't allow for setting the content type of the response based on the view requested. To get around this I've written my own ViewResolver that looks at the View name and sets the Content Type based on that - so any view name that ends in .css will have a Content Type of text/css. This bit also works great.

The problem is that in order to get my view name to be style.css I need to actually request style.css.css, because the UrlFilenameViewController strips the extension off to get the view name it is using. How do I stop this happening so that "/style.css" actually resolves to a view of "style.css" and thus to the "style.css.ftl" template?

A: 

I suggest subclassing UrlFilenameViewController and overriding the extractViewNameFromUrlPath() method to just return the path as the view name.

You could also file an issue on the SpringSource JIRA asking them to make this configurable.

skaffman