简体   繁体   English

如何最好地使用带有Spring servlet容器的JTidy?

[英]How to best use JTidy with a Spring servlet container?

I have a Java servlet container using the Spring Framework. 我有一个使用Spring Framework的Java servlet容器。 Pages are generated from JSPs using Spring to wire everything up. 使用Spring从JSP生成页面以连接所有内容。 The resulting HTML sent to the user isn't as, well, tidy as I'd like. 发送给用户的结果HTML并不像我想的那样整洁。 I'd like to send the HTML to Tidy right before it's sent to the client browser. 我想在将HTML发送到客户端浏览器之前将其发送到Tidy。

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? 关于如何在Spring中干净利落地工作的建议?

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. 最好的办法是删除所有空格并尽可能地压缩HTML。 The users see the rendered HTML, and mostly don't care about its structure and indentation. 用户看到呈现的HTML,并且大多不关心它的结构和缩进。 If you want the user to view the HTML he can use an HTML beautifier on the HTML on his machine. 如果您希望用户查看HTML,他可以在他的机器上的HTML上使用HTML美化器。

More Info 更多信息

JTidy has a servlet filter which you can apply to your jsps. JTidy有一个servlet过滤器 ,可以应用于你的jsps。 Just add the jtidy jar to the WEB-INF/lib and the following lines to the web.xml: 只需将jtidy jar添加到WEB-INF / lib,然后将以下行添加到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>

没有用过我自己,但我认为Spring根本不应该参与这个过程,这个jtidy servlet扩展应该足够你了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM