Solved

Remove all extra white space of outbound pages Tomcat JSP

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
countHi challenge 25 98
Tools or ways to handle development of complex web applications 4 100
parentbit challenge 3 73
groovy example issue 10 89
This exercise is about for the following scenario: Dmgr and One node with 2 application server. Each application server contains it owns application. Application server name as follows server1 contains app1 server2 contains app1 Prereq…
Most of the developers using Tomcat find it easy to configure the datasource in Server.xml and use the JNDI name in the code to get the connection.  So the default connection pool using DBCP (or any other framework) is made available and the life go…
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.

911 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

19 Experts available now in Live!

Get 1:1 Help Now