Removing Empty Lines and whitespaces genereted by JSP

I have been working on a JSP page which was generating emtpy lines & extra whitespaces. I found an Oracle’s document mentioning about this issue.

Here’s what document says

“White space included in the template text of JSP pages is preserved by default. This can have undesirable effects. For example, a carriage return added after a taglib directive would be added to the response output as an extra line. If you want to eliminate the extra white space from the page, you can add a trim-directive-whitespaces element to a jsp-property-group element in the deployment descriptor and set it to true.”

There are two ways in which this issue can be solved.

 

  1. Insert the following directive in your JSP file
<%@ page trimDirectiveWhitespaces="true" %>

 

2.Add the following configuration to your web.xml

<init-param>
    <param-name>trimSpaces</param-name>
    <param-value>true</param-value>
</init-param>

Hope this helps you.

Author: Ahmed I

I am a Linux System Admin

Leave a comment