﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-秒你所不能秒</title><link>http://www.blogjava.net/qqxjj/</link><description /><language>zh-cn</language><lastBuildDate>Wed, 06 May 2026 23:34:18 GMT</lastBuildDate><pubDate>Wed, 06 May 2026 23:34:18 GMT</pubDate><ttl>60</ttl><item><title>删除JSP输出的空行</title><link>http://www.blogjava.net/qqxjj/archive/2012/09/06/387145.html</link><dc:creator>人间极乐</dc:creator><author>人间极乐</author><pubDate>Thu, 06 Sep 2012 01:47:00 GMT</pubDate><guid>http://www.blogjava.net/qqxjj/archive/2012/09/06/387145.html</guid><wfw:comment>http://www.blogjava.net/qqxjj/comments/387145.html</wfw:comment><comments>http://www.blogjava.net/qqxjj/archive/2012/09/06/387145.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/qqxjj/comments/commentRss/387145.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/qqxjj/services/trackbacks/387145.html</trackback:ping><description><![CDATA[当你在客户端用view source看JSP生成的代码时，会发现有很多空行，他们是由&lt;%...%&gt;后的回车换行而生成的，也就是说每一行由&lt;%...%&gt;包含的JSP代码到客户端都变成一个空行，虽然不影响浏览，但还是希望能把他们删掉<br /><br /><p>办法如下：（网上收集整理）</p><p>1. 支持JSP 2.1+ ，在每个要去空行的页面里包含下面代码：</p><p><font color="#3366ff"><strong> </strong></font> </p><div style="background: rgb(230, 230, 230); padding: 4px 5.4pt; border: 0.5pt solid windowtext; width: 95%; word-break: break-all;"><div><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" /><span style="color: rgb(0, 0, 0);">&lt;%</span><span style="color: rgb(0, 0, 0);">@ page trimDirectiveWhitespaces</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">true</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">%&gt;</span></div></div><p>&nbsp;</p><p><font color="#ff0000"><strong>未测试，因为在每个页面加不方便。或者也可以写在一个JSP上，其他JSP来include</strong></font></p><p><br />2. 支持servlet 2.5+, 即 web.xml的 XSD版本为2.5，在web.xml中加入如下代码</p><p><font color="#3366ff"><strong> </strong></font> </p><div style="background: rgb(230, 230, 230); padding: 4px 5.4pt; border: 0.5pt solid windowtext; width: 95%; word-break: break-all;"><div><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" /><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">jsp</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">config</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">jsp</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">property</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">group</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">url</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">pattern</span><span style="color: rgb(0, 0, 0);">&gt;*</span><span style="color: rgb(0, 0, 0);">.jsp</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">url</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">pattern</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">trim</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">directive</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">whitespaces</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">trim</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">directive</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">whitespaces</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">jsp</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">property</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">group</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" />&nbsp;&nbsp;&nbsp; </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">jsp</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">config</span><span style="color: rgb(0, 0, 0);">&gt;</span></div></div><p> </p><p><strong><font color="#ff0000">网上说在tomcat 6.0.14下测试成功，我在6.0.35上未起作用，用了第三种办法生效了。</font></strong></p><p><br />3. Tomcat 5.5.x+，在Tomcat安装目录/conf/web.xml中找到名叫"jsp"的servlet，添加下面一段代码：</p><p> </p><div style="background: rgb(230, 230, 230); padding: 4px 5.4pt; border: 0.5pt solid windowtext; width: 95%; word-break: break-all;"><div><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" /><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">init</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">param</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">param</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">trimSpaces</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">param</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">param</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">value</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 255);">true</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">param</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">value</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" />&nbsp;&nbsp;&nbsp; </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">init</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">param</span><span style="color: rgb(0, 0, 0);">&gt;</span></div></div><img src ="http://www.blogjava.net/qqxjj/aggbug/387145.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/qqxjj/" target="_blank">人间极乐</a> 2012-09-06 09:47 <a href="http://www.blogjava.net/qqxjj/archive/2012/09/06/387145.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>