I have code (now in github) like :
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" %>
where :
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"%>
directive in my top.jsp
file ? Believe me it does nothing. Should I worry that the <%@ page session="false"%>
is similarly ignored ?
Thanks
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.
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.