如何在Spring servlet容器中最好地使用JTidy? [英] How to best use JTidy with a Spring servlet container?

查看:116
本文介绍了如何在Spring servlet容器中最好地使用JTidy?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Spring框架的Java servlet容器。使用Spring从JSP生成页面以将所有内容联系起来。发送给用户的结果HTML并不像我想的那样整齐。我想在将HTML发送到客户端浏览器之前将HTML发送给Tidy。



我将设置它在开发中工作并在生产中关闭;从我的角度来看,它是一个赢家,因为它会让我更容易维护。



关于如何在Spring中干净利落地完成这项工作的建议?

解决方案

你为什么想这样做?最好的办法是尽可能地去除所有空格并压缩HTML。用户看到呈现的HTML,并且大多不关心其结构和缩进。如果你希望用户查看HTML,他可以在他的机器上的HTML上使用HTML美化工具。

更多信息

JTidy有一个 servlet过滤器,您可以将其应用于您的jsps。只需将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>


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?

解决方案

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>

这篇关于如何在Spring servlet容器中最好地使用JTidy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆