当从另一个jsp包含时,<%@ page pageEncoding ="UTF-8"%>被忽略

Mr_*_*s_D 11 encoding jsp jsp-tags include tomcat7

我有代码(现在在github中),如:

my.jsp(一个通用的jsp - 所有我的jspS或多或少都遵循这个模式):

<%@ include file="include/top.jsp" %>
<title>THE TITLE</title>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="include/head.jsp" %>
<%@ include file="include/no_menu.jsp" %>
CONTENT
<%@ include file="include/bottom.jsp" %>
Run Code Online (Sandbox Code Playgroud)

其中:

top.jsp:

<%@ page session="false"%>
<%@ include file="tag_libs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Run Code Online (Sandbox Code Playgroud)

head.jsp:

<link href="${pageContext.request.contextPath}/css/twoColFixLtHdr.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div class="container"><!-- closes in bottom -->
        <div class="header"><!-- closes in menu -->
            <p>
                <a href="home"> <img src="${pageContext.request.contextPath}/images/logo7.jpg"
                    alt="Ted 2012 Logo" name="Ted 2012 Logo" id="Ted_2012_Logo"
                    style="background: display:block; padding: 5px 20px; margin-left: 150px; border-style: solid" /></a>
            </p>
            <hr />
Run Code Online (Sandbox Code Playgroud)

no_menu.jsp:

</div>
<div class="content">
Run Code Online (Sandbox Code Playgroud)

bottom.jsp:

        </div>
        <div class="footer">
            <p>
                blah
            </p>
        </div>
    </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

如你所见 - 或者你可以接受我的话 - 标签正确平衡.我的问题是 - 为什么我不能包括

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
Run Code Online (Sandbox Code Playgroud)

我的top.jsp文件中的指令?相信我它什么都不做.我是否应该担心<%@ page session="false"%>同样被忽略

谢谢

gd1*_*gd1 14

您不需要将@page指令放在每个包含的JSP文件中.严格来说,它们不是JSP,而是包含在JSP 中的文本文件.@include相当于将包含页面中的文本剪切并粘贴到主JSP中.这就像#includeC中的指令.

请尽量把<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>作为第一个你的主JSP文件(即一个包括其他)的路线,不要把它在其他地方.
希望能帮助到你.