JSP Document/JSPX: what determines how tabs/space/linebreaks are removed in the output?

Posted by NoozNooz42 on Stack Overflow See other posts from Stack Overflow or by NoozNooz42
Published on 2010-05-29T12:48:17Z Indexed on 2010/05/29 13:52 UTC
Read the original article Hit count: 391

Filed under:
|
|
|

I've got a "JSP Document" ("JSP in XML") nicely formatted and when the webpage is generated and sent to the user, some linebreaks are removed.

Now the really weird part: apparently the "main" .jsp always gets all its linebreak removed but for any subsequent .jsp included from the main .jsp, linebreaks seems to be randomly removed (some are there, others aren't).

For example, if I'm looking at the webpage served from Firefox and ask to "view source", I get to see what is generated.

So, what determines when/how linebreaks are kept/removed?

This is just an example I made up... Can you force a .jsp to serve this:

<body><div id="page"><div id="header"><div class="title">...

or this:

<body>
  <div id="page">
    <div id="header">
      <div class="title">...

?

I take it that linebreaks are removed to save on bandwidth, but what if I want to keep them? And what if I want to keep the same XML indentation as in my .jsp file?

Is this doable?

EDIT

Following skaffman's advice, I took a look at the generated .java files and the "main" one doesn't have lots of out.write but not a single one writing tabs nor newlines. Contrary to that file, all the ones that I'm including from that main .jsp have lots of lines like:

out.write("\t...\n");

So I guess my question stays exactly the same: what determines how tabs/space/linebreaks are included/removed in the output?

© Stack Overflow or respective owner

Related posts about java

Related posts about jsp