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

查看:61
本文介绍了从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天全站免登陆