*
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "tomcat 5.0 whitespace surgery" Watch "tomcat 5.0 whitespace surgery" New topic
Author

tomcat 5.0 whitespace surgery

Sam Szabo
Greenhorn

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.

thanks
Sam
Sam Szabo
Greenhorn

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"/>
</replaceregexp>

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

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
Greenhorn

Joined: Nov 30, 2006
Posts: 2
Hi
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.
<filter>
<filter-name>trimFilter</filter-name>
<filter-class>com.cj.trim.trimFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>trimFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>trimFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>

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


Regards,<br />B.Sridhar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: tomcat 5.0 whitespace surgery