Announcement Announcement Module
Collapse
No announcement yet.
SimpleUrlHandlerMapping and web sources Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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" />

    Comment


    • #3
      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>

      Comment

      Working...
      X