Results 1 to 3 of 3

Thread: SimpleUrlHandlerMapping and web sources

  1. #1
    Join Date
    Aug 2007
    Posts
    7

    Default SimpleUrlHandlerMapping and web sources

    Hi everyone!
    I have a problem with my web application based on Spring MVC. There is my web.xml url mapping :

    Code:
        <servlet>
            <servlet-name>dispatcher</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>dispatcher</servlet-name>
            <url-pattern>*.ftl</url-pattern>
        </servlet-mapping>
    
        <servlet-mapping>
            <servlet-name>dispatcher</servlet-name>
            <url-pattern>/*</url-pattern>
        </servlet-mapping>
    and here is my dispatcher-servlet.xml file mapping :

    Code:
       <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
         <property name="mappings">
              <props>
    			  <prop key="/">indexController</prop>
               </props>
              </property>
        </bean>
    As I understand all queries will be redirected to the urlMapping bean. It worsk fine, as expected.
    The problem is that I cant get to my web resources (css, js files e.t.c.) my links lead to nowhere, so when im trying to load something like
    HTML Code:
    <link href="/css/crazygrace.css" type="text/css" rel="stylesheet" />
    it fails, as I can understand it redirects the path to the urlMapping handler which in turn fails to find url that is not specified in the config.

    is there something like best practice solution for this issue or may be Im doing something wrong?

  2. #2
    Join Date
    Jan 2010
    Location
    London
    Posts
    11

    Default

    Have you tried pointing to the css file withouth putting the first slash in the path? , something like:
    HTML Code:
    <link href="css/crazygrace.css" type="text/css" rel="stylesheet" />

  3. #3
    Join Date
    Jan 2010
    Posts
    27

    Default

    In order to get hold of static content, you could also try putting mappings to your default servlet within your web.xml file.

    An example is shown below, however this is for JBoss. The default servlet-name maybe different depending on the server.

    Code:
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.css</url-pattern>
    	</servlet-mapping>
    
      <servlet-mapping>
        	<servlet-name>default</servlet-name>
        	<url-pattern>*.js</url-pattern>
      </servlet-mapping>

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
  •