如何最好地将 JTidy 与 Spring servlet 容器一起使用?

发布于 2024-08-08 16:50:20 字数 221 浏览 4 评论 0原文

我有一个使用 Spring 框架的 Java servlet 容器。页面是使用 Spring 连接所有内容从 JSP 生成的。发送给用户的生成的 HTML 并不像我希望的那样整洁。我想在将 HTML 发送到客户端浏览器之前将其发送到 Tidy。

我将把它设置为在开发中工作并在生产中关闭;从我的角度来看,它是一个胜利者,因为它将使我更容易维护。

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

望笑 2024-08-15 16:50:20

你为什么要这么做?最好的办法是删除所有空格并尽可能压缩 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>

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>
£烟消云散 2024-08-15 16:50:20

我自己没有使用过,但我认为 spring 根本不应该参与这个过程,这个 jtidy servlet 扩展 应该足以满足您的需求。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文