How to remove whitespaces in tomcat with Magnolia (CMS) or OpenCms

If you have worked with Magnolia (CMS) or OpenCms (or JSPs in general) before, you may experienced the problem with unwanted whitespaces in the resulting HTML.Off course in Magnolia you rarely work with JSP's anyway. There are ways to avoid this by configuring the web.xml in the following way:


But this doesn't seem to work with OpenCms, my guess that is because of it's servlet-version. So I choose the way of inserting the directive

<%@ page trimDirectiveWhitespaces="true" %>

into every JSP, which is not so elegant, but it works. Only I didn't want to do this manualy, so I wrote the following bash-script:

for f in `find . -iname "*.jsp"`;
  echo file $f;
  sed -i.bak '1i\
<%@ page trimDirectiveWhitespaces=\"true\" %>
  ' ${f}
#echo $(head -n 1 $f)

I'm available as a freelancer (Freiberufler) for Magnolia (CMS) or OpenCms projects.