Announcement Announcement Module
Collapse
No announcement yet.
How to server static files with UrlFilenameViewController? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to server static files with UrlFilenameViewController?

    I'm using annotation-driven configuration and I've added the following to my servlet-context.xml:

    Code:
    <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
      <property name="defaultHandler">
      <!-- If no @Controller match, map path to a view to render; e.g. the "/index" path would map to the view named "index". -->  
      <bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
      </property>
    </bean>
    The file (style.css) resides in WebContent folder, but it is not served. I get this message in the log file:
    Code:
    noHandlerFound No mapping found for HTTP request with URI [/sso-web/style.css] in DispatcherServlet
    Generally, I would rather serve static files as just files with web server, but I don't want an extra path in the url so that I can change servlet mapping from / to say 'app', just to be able to access static files.

    Thanks,
    Miha.

  • #2
    I suggest a read of the reference guide, serving static resources is explained in there...

    Comment


    • #3
      Marten, works like a charm, thank you.

      Regards.

      Comment


      • #4
        One more thing: is there a preferred way to 'know' what is the "context-path" in the view?

        For instance, if I create links as /media/style.css in a view template, and application is deployed as /my-app/ within servlet container, then obviously, /media does not point to the right place.

        I guess that setting up a global variable which is available to the view engine is the way to go?

        Comment

        Working...
        X