So I have a Tiles layout that has some attributes in it. It looks like so:
<body>
<div id="header">
<tiles:insertAttribute name="header" />
</div>
<div id="content">
<tiles:insertAttribute name="content" />
</div>
<div id="footer">
<tiles:insertAttribute name="footer" />
</div>
</body>
My header element file looks like the following:
<h1>Header</h1>
<div id="nav">
<ul>
<li>Nav Item 1</li>
<li>Nav Item 2</li>
</ul>
<hr />
</div>
What's annoying me is that the indentation of the header element isn't respected. The rendered output for the header looks like so:
<body>
<div id="header">
<h1>Header</h1>
<div id="nav">
<ul>
<li>Nav开发者_运维知识库 Item 1</li>
<li>Nav Item 2</li>
</ul>
<hr />
</div>
</div>
....
I'd like it to look like this:
<body>
<div id="header">
<h1>Header</h1>
<div id="nav">
<ul>
<li>Nav Item 1</li>
<li>Nav Item 2</li>
</ul>
<hr />
</div>
</div>
....
Is there a way to configure Tiles or add some sort of filter to preserve the indentation in the final rendered output? Lastly, I'm currently trimming whitespace with:
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<trim-directive-whitespaces>true</trim-directive-whitespaces>
</jsp-property-group>
</jsp-config>
I don't know a way to configure tiles to preserve indentation, but it's not hard to make a servlet filter that cleans up the response html before sending it to the browser. There may be many already available on-line - one I found by a quick search was a JTidy filter.
精彩评论