<%@ page pageEncoding =“UTF-8”%>当从另一个jsp包含时忽略 [英] <%@ page pageEncoding="UTF-8"%> ignored when included from another jsp
问题描述
我有代码(现在在 github )喜欢:
I have code (now in github) like :
my.jsp (一个通用的jsp - 我所有的jspS或多或少都遵循这种模式):
my.jsp (a generic jsp - all my jspS follow this pattern more or less) :
<%@ 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>
如你所见 - 或者你可以接受我的话 - 标签平衡正确。我的问题是 - 为什么我不能包含
As you see - or you can take my word for it - the tags balance correctly. My question is - why can't I include the
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
指令在我的 top.jsp
文件?相信我什么都不做我应该担心,<%@ page session =false%>
同样被忽略?
directive in my top.jsp
file ? Believe me it does nothing. Should I worry that the <%@ page session="false"%>
is similarly ignored ?
谢谢
推荐答案
你不需要把 @page
指令在每个包含JSP文件。严格来说,它们不是JSP,它们是包含在JSP中的文本文件。 @include
相当于将包含的页面中的文本直接剪切并粘贴到主JSP中。这就像C中的 #include
指令。
You shoudn't need to put the @page
directive in each included JSP file. Strictly speaking, they are not JSPs, they are text files being included into a JSP. @include
is equivalent to cutting and pasting the text from your included page right into your main JSP. It's like the #include
directive in C.
请尝试将<% @ page language =javacontentType =text / html; charset = UTF-8pageEncoding =UTF-8%>
作为第一个您的主要JSP文件(即其中包括其他文件),并且不要放在其他地方。
希望它有帮助。
Please try to put <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
as the very first line of your main JSP file (i.e. the one which includes the others), and don't put it anywhere else.
Hope it helps.
这篇关于<%@ page pageEncoding =“UTF-8”%>当从另一个jsp包含时忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!