title: Clean up user input from unwanted HTML in a Spring web application
body: <p>I need to tidy user input in a web application so that I remove certain HTML-tags and encode &lt; to &amp;gt etc.</p>
  <p>I've made a couple of simple util methods that strips the HTML, but I find myself adding these EVERYWHERE in my application.</p>
  <p>Is there a smarter way to tidy the user input? E.g. in the binding process, or as a filter somehow?</p>
  <p>I've seen JTidy that can act as a servlet filter, but I'm not sure that this is what I want because I need to clean user input, not output of my JSP's.</p>
  <p>From  JTidy's homepage:</p>
  <blockquote>
  <p>It can be used as a tool for cleaning up malformed and faulty HTML generated by your dynamic web application.</p>
  <p>It can Validate HTML without changing the output and generate warnings for each page so you could identify JSP or Servlet that need to be fixed.</p>
  <p>It can save you hours of time. The more HTML you write in JSP or Servlets, the more time you will save. Don't waste time manually looking for problems, figuring out why your HTML doesn't display like it should.</p>
  <p>In addition to JTidy validation you could submit dynamically generated pages to online HTML validators for example W3C Markup Validation Service, WAVE Accessibility Tool or WDG HTML Validator even if you are behind the firewall.</p>
  </blockquote>