Results 1 to 4 of 4

Thread: How to server static files with UrlFilenameViewController?

  1. #1
    Join Date
    Aug 2009
    Posts
    22

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    I suggest a read of the reference guide, serving static resources is explained in there...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Aug 2009
    Posts
    22

    Default

    Marten, works like a charm, thank you.

    Regards.

  4. #4
    Join Date
    Aug 2009
    Posts
    22

    Default

    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?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •