How to remove blank lines from the JSP output

A source of annoyance with the JSP output, where all the JSP directives are replaced with blank lines in the final output has been addressed in JSP 2.1. Now if you want to get rid of all the blank lines in your JSP output, simply add the line <%@page trimDirectiveWhitespaces="true"%> to the top of your JSP. I wish this was the default.

13 Responses to “How to remove blank lines from the JSP output”

  1. Vignesh Ravi Says:

    Thanks a lot. I was stuck with exactly this problem and the solution given here worked wonderfully well. Thanks again Shahram.

  2. Florian Hüter Says:

    Thanks for this little hint. I’ve already known the option to suppress blank lines per web.xml but in my special case I needed it for only one JSP file.

    But one question remained: Eclipse marks this attribute with an “undefined attribute name” warning but in my webapp it works exactly as expected. Any idea?

    Thanks again, Florian

  3. Jay Says:

    I’ve been looking into how to remove the warning in eclipse as well,but so far no luck. Let me know if you figure this out.

  4. manoj Says:

    thanks a lot.

  5. Vasyl Khrystyuk Says:

    there is another solution.
    Add this to your web.xml:




  6. Vasyl Khrystyuk Says:

    you shuld configurate your filter becouse it didn’t work as expect

  7. Shailesh Says:

    This tag only works for JSP 2.1 onwards. for earlier version any solution?

  8. Phan Tình Phong Says:



    Oh, Thankyou!

  10. Ian Says:

    Thank you very much!!

  11. Donna Says:

    Thanks from me too. Page from 2007 still helpful in 2013!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: