2013/11/10

去除JSP自動生成的空行

JSP中的程式碼的部分 <% ..... %> 在顯示網頁原始碼時會產生空白的行數


Tomcat 5.5.x+

在conf/web.xml中的servlet/jsp區段加入
<init-param>
  <param-name>trimSpaces</param-name>
  <param-value>true</param-value>
</init-param>

Tomcat 6.0.x+ servlet 2.5+

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

JSP 2.1+

在jsp頁面中加入

<%@ page trimDirectiveWhitespaces="true" %>

沒有留言:

張貼留言