在JSP中<[email protected] file="">是比較常用的包含其他文件的一種手段,但是在使用時一不小心也會出錯,如下代碼:
<[email protected] file="">index.jsp:
<%@ page="" language="java" contenttype="text/html; charset=UTF-8" pageencoding="UTF-8"><%@include file="./include.jsp"> <%@include file="./include.jsp"><%@ page="" language="java" contenttype="text/html; charset=UTF-8" pageencoding="UTF-8">include.jsp
<%@ page="" language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8"> Hello World!<%@ page="" language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8">當訪問index.jsp時會出現如下錯誤:
為什麼會出現這樣的問題,很簡單:index.jsp中contentType="text/html; charset=UTF-8"的charset屬性值和include.jsp中“contentType="text/html; charset=utf-8"”的charset屬性值不同——此處是區分大小寫的。