Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that requests for the static content go to the dispatcherServlet, because it's mapped as <code>&lt;url-pattern&gt;/&lt;/url-pattern&gt;</code>. It's a very common problem in applications with "RESTful" URLs (that is, without any prefix in the <code>DispatcherServlet</code> mapping). </p> <p>There are several possible ways to solve this problem:</p> <hr> <p><strong>Since Spring 3.x the preferred way to access static resources is to use <code>&lt;mvc:resources&gt;</code>:</strong> <code>web.xml</code>:</p> <pre><code>&lt;servlet-mapping&gt; &lt;servlet-name&gt;springapp&lt;/servlet-name&gt; &lt;url-pattern&gt;/&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <p>Spring config:</p> <pre><code>&lt;!-- Handles GET requests for /resources/** by efficiently serving static content in the ${webappRoot}/resources dir --&gt; &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt; </code></pre> <p>See also <a href="http://blog.springsource.com/2009/12/21/mvc-simplifications-in-spring-3-0/" rel="nofollow noreferrer">MVC Simplifications in Spring 3</a></p> <hr> <p><strong>1. Use URL rewrite filter</strong><br> See <code>mvc-basic</code> example <a href="http://blog.springsource.com/2009/12/21/mvc-simplifications-in-spring-3-0/" rel="nofollow noreferrer">here</a></p> <p><strong>2. Set a prefix for the <code>default</code> servlet:</strong></p> <pre><code>&lt;servlet-mapping&gt; &lt;servlet-name&gt;default&lt;/servlet-name&gt; &lt;url-pattern&gt;/static/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <p>That is, request for <code>/static/images/image.png</code> will return the file named <code>/images/image.png</code> However, this way is incompatible across different servlet containers (doesn't work in Jetty), see workarounds <a href="https://stackoverflow.com/questions/132052/servlet-for-serving-static-content/837020#837020">here</a></p> <p><strong>3. Set static content extensions for the <code>default</code> servlet:</strong></p> <pre><code>&lt;servlet-mapping&gt; &lt;servlet-name&gt;default&lt;/servlet-name&gt; &lt;url-pattern&gt;*.png&lt;/url-pattern&gt; &lt;url-pattern&gt;*.js&lt;/url-pattern&gt; &lt;url-pattern&gt;*.css&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <p><strong>4. Do not use RESTful URLs, use URLs with prefix:</strong></p> <pre><code>&lt;servlet-mapping&gt; &lt;servlet-name&gt;springapp&lt;/servlet-name&gt; &lt;url-pattern&gt;/app&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <p><strong>5. Do not use RESTful URLs, use URLs with extension:</strong></p> <pre><code>&lt;servlet-mapping&gt; &lt;servlet-name&gt;springapp&lt;/servlet-name&gt; &lt;url-pattern&gt;*.do&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload