[转]删除JSP编译后的空行

JSP编译后,原< %...% >会变成空行,如果不再框架中加入过滤压缩的话,既不好看,又浪费网络资源。

Google一番找出如下三种解决办法:

1. 在Tomcat安装目录/conf/web.xml中找到名叫"jsp"的servlet,添加一个初始参数:

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


Tomcat 5.5下利落通过。
trimSpaces的含义为:

<!--   trimSpaces          Should white spaces in template text between   -->
  <!--                       actions or directives be trimmed?  [false]     -->


2.  在web.xml中加入如下代码

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

需要servlet 2.5+支持,未验证。2.4下不通过。

3. 在JSP页首包含下面代码:

<%@ page trimDirectiveWhitespaces="true" %>
需要 JSP 2.1+  支持,未验证。2.0下不通过。


你可能感兴趣的:(jsp,编译,空行,去除)