首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

JSP JSTL EL 剔除空行 <%@ page trimDirectiveWhitespaces="true" %>

2013-08-14 
JSP JSTL EL 删除空行 %@ page trimDirectiveWhitespacestrue %%@ page trimDirectiveWhitespaces

JSP JSTL EL 删除空行 <%@ page trimDirectiveWhitespaces="true" %>

<%@ page trimDirectiveWhitespaces="true" %>


这个命令可以使jsp输出的html时去除多余的空行(jsp上使用EL和tag会产生大量的空格和空行)。

?

但是这个命令是从JSP2.1规范以后才得到支持。

所以在tomcat 6.0之前的版本上如果使用这个命令就会抛出异常:

Page directive has invalid attribute: trimDirectiveWhitespaces

?

解决方法是:

1.升级tomcat至6.0以上版本

2.Tomcat 5.5.x+,不要使用trimDirectiveWhitespaces,改用这种方法:

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

?

JSP JSTL EL 剔除空行 <%@ page trimDirectiveWhitespaces="true" %><init-param>
JSP JSTL EL 剔除空行 <%@ page trimDirectiveWhitespaces="true" %>???????<param-name>trimSpaces</param-name>
JSP JSTL EL 剔除空行 <%@ page trimDirectiveWhitespaces="true" %>???????<param-value>true</param-value>
JSP JSTL EL 剔除空行 <%@ page trimDirectiveWhitespaces="true" %></init-param>??查看JSP版本可以使用下面的命令:JSP version: <%= JspFactory.getDefaultFactory().getEngineInfo().getSpecificationVersion() %>??

在web.xml中加上这个配置,看看效果如何

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

??更多信息可以参考:http://blog.csdn.net/xuhaiyang/archive/2008/05/23/2472591.aspx

热点排行