我有代码(现在在 github)喜欢: my.jsp(一个通用的jsp – 我的所有jspS或多或少遵循这种模式): %@ include file="include/top.jsp" %titleTHE TITLE/title%@ page language="java" contentType="text/html; charset=UTF-8" p
          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" %> 
 其中:
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" />
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 /> 
 no_menu.jsp:
</div> <div class="content">
bottom.jsp:
</div>
        <div class="footer">
            <p>
                blah
            </p>
        </div>
    </div>
</body>
</html> 
 如你所见 – 或者你可以接受我的话 – 标签平衡正确.我的问题是 – 为什么我不能包括
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%> 
 指令在我的top.jsp文件?相信我什么都不做我应该担心<%@ page session =“false”%>同样被忽略?
谢谢
您不需要在每个包含的JSP文件中放置@page指令.严格来说,它们不是JSP,它们是包含在JSP中的文本文件. @include相当于将包含的页面中的文本直接剪切并粘贴到主JSP中.这就像C中的#include指令.请尝试放置<%@ page language =“java”contentType =“text / html; charset = UTF-8”pageEncoding =“UTF-8”%>作为您的主JSP文件(即包括其他文件的文件)的第一行,不要将其放在其他位置.希望它有帮助.
