How to best use JTidy with a Spring servlet container?

喜你入骨 提交于 2019-12-10 05:49:45

问题


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?


回答1:


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>



回答2:


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.



来源:https://stackoverflow.com/questions/1589745/how-to-best-use-jtidy-with-a-spring-servlet-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!