views:

281

answers:

2

I have a Java servlet container using the Spring Framework. Pages are generated from JSPs using Spring to wire everything up. The resulting HTML sent to the user isn't as, well, tidy as I'd like. I'd like to send the HTML to Tidy right before it's sent to the client browser.

I'll set it up to work in development and be turned off in production; it's a winner, from my point of view, as it'll gain me more ease of maintenance.

Suggestions on how to make that work cleanly in Spring?

+2  A: 

Why do you want to do that? The best thing to do is to remove all whitespaces and compact the HTML as much as possible. The users see the rendered HTML, and mostly don't care about its structure and indentation. If you want the user to view the HTML he can use an HTML beautifier on the HTML on his machine.

More Info

JTidy has a servlet filter which you can apply to your jsps. Just add the jtidy jar to the WEB-INF/lib and the following lines to the web.xml:

<filter>
    <filter-name>JTidyFilter</filter-name>
    <filter-class>org.w3c.tidy.servlet.filter.JTidyFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>JTidyFilter</filter-name>
    <servlet-name>DispatcherServlet</servlet-name>
</filter-mapping>
<filter-mapping>
    <filter-name>JTidyFilter</filter-name>
    <url-pattern>*.jsp</url-pattern>
</filter-mapping>
David Rabinowitz
I can just turn it on in development, and turn it off in production; I gain some ease of maintenance on the way.
Dean J
Edited original question to incorporate that (important) bit.
Dean J
You have a small typo "servlet-namen" in the above XML snippet.
Andrew Swan
@Andrew thanks, fixed
David Rabinowitz
+2  A: 

Haven't used myself but I don't think spring should be involved in this process at all, with this jtidy servlet extension should be enough for you.

pedromarce
That might be exactly what I was looking for; didn't see any links to it from the JTidy main project, and missed it in searches. (Thanks! Will dig farther.)
Dean J