Solved

Remove all extra white space of outbound pages Tomcat JSP

Posted on 2007-11-30
4
5,426 Views
Last Modified: 2013-12-02
I am trying to find a good easily implemented way to remove all extra unseen white space in  the HTML code being returned by tomcat to the client's computer. So for instance if there was a way to put a layer between tomcat and the and the user that just compresses the file by removing extra white space.

If you view source of say msn you will find no new lines or tabs. they strip all this out to try and reduce the download size of a page. Any suggestions on how to output a compressed file without having to update the source code for each page?
0
Comment
Question by:Isisagate
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
mrcoffee365 earned 500 total points
ID: 20383419
You can write your JSP pages to reduce white space by putting JSP directives on the same line (no newlines).  For example,
<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1"%><%
 // code here
 // last code line here  %><html><head> [rest of page here]

It's harder for the programmer to read, which is why most people don't write JSP code that way.

You can add a filter to Tomcat to strip all unseen white space in the returned page.

For Tomcat 5.5+ you can add the trimSpaces param to your conf/web.xml and set it to true.

There is a great discussion about different ways to handle trimming white space from JSP pages here:
http://raibledesigns.com/rd/entry/trim_spaces_in_your_jsp


0
 
LVL 27

Expert Comment

by:rrz
ID: 20383705
JSP 2.1 has this. Does it help you ?
<%@ page trimDirectiveWhitespaces="true" %>
0
 
LVL 11

Author Closing Comment

by:Isisagate
ID: 31411930
Great solutions Exactly what I wanted
0
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 20385010
Great -- glad to help.
0

Featured Post

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

-Xmx and -Xms are the two JVM options often used to tune JVM heap size.   Here are some common mistakes made when using them:   Assume BigApp is a java class file for the below examples. 1.         Missing m, M, g or G at the end …
There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question