title: Stop submit request using Java filter
body: <p>I have a Java filter that allows continue or not the request depending of the URL, however I have a problem when the request come from a form.</p>
  
  <p>Let's say I have a HTML form with an action and a submit button, then the filter evaluate the request, if the request is invalid I need to stop the request:</p>
  
  <pre><code>public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
      String requestDestination = ((HttpServletRequest) servletRequest).getRequestURI();
      if ( requestDestination.contains("/url") ) {
          HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;
          Cookie denied = new Cookie("denied", "url");
          httpResponse.addCookie(denied);
          return;
      }
  }
  </code></pre>
  
  <p>The problem is that despite this action, the browser goes to this URL showing an empty page off course, but what I need is to stop this default behavior, just leaving the user in the same page.</p>
  
  <p>I can't use JavaScript since I don't know exactly who is triggering the request.</p>