从jsp输出中去除空格 [英] Strip whitespace from jsp output

查看:42
本文介绍了从jsp输出中去除空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从jsp页面的输出中去除多余的空格?有没有我可以在 web.xml 上翻转的开关?是否有特定于 Tomcat 的设置?

How can I strip out extra whitespace from jsp pages' output? Is there a switch I can flip on my web.xml? Is there a Tomcat specific setting?

推荐答案

trimWhiteSpaces 指令应该可以实现这一点,

There is a trimWhiteSpaces directive that should accomplish this,

在您的 JSP 中:

<%@ page trimDirectiveWhitespaces="true" %>

或者在 jsp-config 部分中您的 web.xml(请注意,这是从 servlet 规范 2.5 开始的.):

Or in the jsp-config section your web.xml (Note that this works starting from servlet specification 2.5.):

<jsp-config>
  <jsp-property-group>
    <url-pattern>*.jsp</url-pattern>
    <trim-directive-whitespaces>true</trim-directive-whitespaces>
  </jsp-property-group>
</jsp-config>

不幸的是,如果您有所需的空间,它可能也需要删除,因此您可能需要在某些位置有一个不间断的空间.

Unfortunately if you have a required space it might also need strip that, so you may need a non-breaking space in some locations.

这篇关于从jsp输出中去除空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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