Error in includign jspf

2019-03-22 04:45发布

问题:

I want to make include jspf into index jsp page , these statements

<%-- any content can be specified here e.g.: --%>
<%@ page pageEncoding="UTF-8" %>

aappears in the index page !!

here's the include line in index page

 <jsp:include page="WEB-INF/jspf/Header.jspf" />

Note : I make head and body in the index page only, can some body tell me why the first lines appears in the index page?

回答1:

JSPF files are intented to be statically included by @include. Its source code becomes then literally part of the parent JSP file. This happens only once, during compiletime.

<%@include file="/WEB-INF/jspf/Header.jspf" %>

If you want a compiletime include with <jsp:include> then just rename .jspf to .jsp. The source code will then be compiled once separately and its output will be generated and included during runtime. This happens then on every request.