title: how to stop servlet?
body: <p>I have a servlet that looks like this:</p>
  
  <pre><code>public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException{
      String param1 = request.getParameter("param1");
      String param2 = request.getParameter("param2");
  
      validateInput(param1, param2, request, response);
  
      //if nothing's wrong with the input, do this and that
  }
  
  
  private void validateInput(String param1, String param2, HttpServletRequest request, HttpServletResponse response) throws IOException{
      boolean fail = false;
  
      //validate input blah blah blah
  
      if (fail){
          PrintWriter out = response.getWriter();
          out.write("invalid input");
          //end process or servlet
      }
  }
  </code></pre>
  
  <p>The idea is that I want to pass <code>param1</code> and <code>param2</code> to function <code>validateInput()</code> to validate whether or not the input is valid. If input is invalid, write a message back and then end the process. My question is <strong>how to end the process?</strong> I'm aware of that calling <code>return;</code> in <code>doPost()</code> will end the process but I'm trying to avoid returning any value from <code>validateInput()</code> to <code>doPost()</code> just for the sake of ending the process. I personally feel that it's more readable this way rather than returning <code>true</code> or <code>false</code> to <code>doPost()</code> and call <code>return;</code> there. Is there a way to do it? Or is it simply impossible?</p>