Solved

Remove all extra white space of outbound pages Tomcat JSP

Posted on 2007-11-30
4
5,382 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 26

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 26

Expert Comment

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
fizzArray3  challenge 1 66
java JDK Download 7 62
wordsWithoutList  challenge 24 73
wordsWithout 49 79
-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 …
Configure Web Service (server application) I. Configure security for Web Services methods First, we need to protect Session bean which implements the service: 1. Open EJB deployment descriptor (ejb-jar.xml) in the EJB project that contains you…
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now