Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This approach works when you want to prevent a certain filter and all the following ones. It should work well if you eg. want to serve some content as static resources within your servlet container instead of letting your application logic (through a filter like GuiceFilter):</p> <p>Map the folder with your static resource files to the default servlet. Create a servlet filter and put it <em>before</em> the GuiceFilter in your web.xml. In your created filter, you can separate between forwarding some requests to the GuiceFilter and others directly to the dispatcher. Example follows...</p> <p><strong>web.xml</strong></p> <pre class="lang-xml prettyprint-override"><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; &lt;filter&gt; &lt;filter-name&gt;StaticResourceFilter&lt;/filter-name&gt; &lt;filter-class&gt;com.project.filter.StaticResourceFilter&lt;/filter-class&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;StaticResourceFilter&lt;/filter-name&gt; &lt;url-pattern&gt;/static/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt; &lt;filter&gt; &lt;filter-name&gt;guiceFilter&lt;/filter-name&gt; &lt;filter-class&gt;com.google.inject.servlet.GuiceFilter&lt;/filter-class&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;guiceFilter&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt; </code></pre> <p><strong>StaticResourceFilter.class</strong></p> <pre><code>public class StaticResourceFilter implements Filter { private final static Logger LOGGER = LoggerFactory.getLogger(StaticResourceFilter.class); private static final String RESOURCE_PATH = "/static/"; @Override public void init(final FilterConfig filterConfig) throws ServletException { LOGGER.info("StaticResourceFilter initialized"); } @Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { String path = ((HttpServletRequest) request).getServletPath(); if (path.toLowerCase().startsWith(RESOURCE_PATH)) { request.getRequestDispatcher(path).forward(request, response); } else { chain.doFilter(request, response); } } @Override public void destroy() { LOGGER.info("StaticResourceFilter destroyed"); } } </code></pre> <p>Unfortunately if you just want to skip a single step in the filter chain while keeping those that follows, this will not work.</p>
    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. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    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