連線到Tomcat伺服器網站(版本編號:apache-tomcat-7.0.62_x64),檢視網頁原始碼時,至少會發現上方有一行空白行,原因是網頁上方宣告,

例如:

<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>

若是在宣告使用其他taglib或引入其他方法,那麼空白行就會更多,

例如:

<%@ page import="java.util.*"%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

 

解決方法:

1.停止執行Tomcat

2.備份Tomcat安裝路徑\conf\web.xml

3.新增參數trimSpaces,將其設定為true

<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>trimSpaces</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>

參數說明如下:

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

4.清除Tomcat安裝路徑\work\內所有資料夾

5.重新啟動Tomcat

 

 

, ,

K 發表在 痞客邦 PIXNET 留言(0) 人氣()