Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Remove all extra white space of outbound pages Tomcat JSP

Posted on 2007-11-30
4
Medium Priority
?
5,548 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 2000 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 28

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
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.
Suggested Courses

972 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