BlogJava-秒你所不能秒http://www.blogjava.net/qqxjj/zh-cnSat, 10 May 2025 10:18:00 GMTSat, 10 May 2025 10:18:00 GMT60删除JSP输出的空行http://www.blogjava.net/qqxjj/archive/2012/09/06/387145.html人间极乐人间极乐Thu, 06 Sep 2012 01:47:00 GMThttp://www.blogjava.net/qqxjj/archive/2012/09/06/387145.htmlhttp://www.blogjava.net/qqxjj/comments/387145.htmlhttp://www.blogjava.net/qqxjj/archive/2012/09/06/387145.html#Feedback0http://www.blogjava.net/qqxjj/comments/commentRss/387145.htmlhttp://www.blogjava.net/qqxjj/services/trackbacks/387145.html

办法如下:(网上收集整理)

1. 支持JSP 2.1+ ,在每个要去空行的页面里包含下面代码:

<%@ page trimDirectiveWhitespaces="true" %>

 

未测试,因为在每个页面加不方便。或者也可以写在一个JSP上,其他JSP来include


2. 支持servlet 2.5+, 即 web.xml的 XSD版本为2.5,在web.xml中加入如下代码

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

网上说在tomcat 6.0.14下测试成功,我在6.0.35上未起作用,用了第三种办法生效了。


3. Tomcat 5.5.x+,在Tomcat安装目录/conf/web.xml中找到名叫"jsp"的servlet,添加下面一段代码:

<init-param>
       
<param-name>trimSpaces</param-name>
       
<param-value>true</param-value>
   
</init-param>


人间极乐 2012-09-06 09:47 发表评论
]]>