Question

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?

Was it helpful?

Solution

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>

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top