The moose likes Tomcat and the fly likes tomcat 5.0 whitespace surgery Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "tomcat 5.0 whitespace surgery" Watch "tomcat 5.0 whitespace surgery" New topic

tomcat 5.0 whitespace surgery

Sam Szabo

Joined: Oct 04, 2006
Posts: 9
Hi guys and gals
I have a client who is requesting that all the extraneous whitespace be removed from the JSP output on their site, believing it is adversely affecting bandwidth and search engine rankings.

I understand there are different settings in 5.5 and 6.0 to automatically do this but upgrading is not an option. So it seems the only way is to remove all newlines and indentation from certain JSP files.

Is there any way to configure an script to run on Ant deploy that automatically deletes all extra whitespace between JSP tag delimeters? We could do it before deployment but that would turn the page into a few very long lines, unmaintainable.

Sam Szabo

Joined: Oct 04, 2006
Posts: 9
it seems the way to do this is add a block to the Ant build target like

<replaceregexp match="\s+" replace=" " flags="g" byline="true">
<fileset dir="${build.home}" includes="**/*.jsp"/>

but I have not tested it yet. If anyone knows different I would appreciate it...
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

The JspServlet in Tomcat (which uses Jasper) has a trimSpaces parameter.
From tomcat/conf/web.xml:

This only prevents Jasper from inserting line breaks between actions and directives. It won't remove spaces that already exist in the JSP source.

As for bandwidth consumption,
You might want to look at the built in gzip capabilities that ship with Tomcat.
From tomcat/conf/server.xml:

I've never heard of whitespace affecting search engine ratings.
Is this something your client can demonstrate or are they just speculating?

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
B Sridhar

Joined: Nov 30, 2006
Posts: 2
I have applied this requirement in my project also.
Pls follow the guidelines as i mentioned below
Try to search in the net to get trimfilter.jar jar file and place this jar file in your lib folder.
and add these tags in your web.xml file also.



otherwise mail your email address to and i will send all the required files to you.

Regards,<br />B.Sridhar
I agree. Here's the link:
subject: tomcat 5.0 whitespace surgery
It's not a secret anymore!