我的一个jsp代码中使用了<jsp:include flush="true" page="head.jsp"></jsp:include>标签,但是这个标签必须放在最开始才能生效,如果在之前加东西都不好用,这是什么原因?我想把它放在中间可以吗?以下是head.jsp中的内容:
<%
String username = (String) request.getSession().getAttribute(
"username");
if (username != null) {
if (request.getAttribute("succ") != null) {
%>
<h2>WEB LIST</h2>
<p align="right"><font color="red" size="4">Welcome ${username}</font></p>
<hr>
<%
} else {
%>
<p align="right"><font color="red" size="4">Welcome ${username}</font></p>
<hr>
<%
}
} else {
%>
<jsp:forward page="error.jsp"></jsp:forward>
<%
}
%>
补充:如果head.jsp中是静态文本就没有问题,
<%
String username = (String) request.getSession().getAttribute(
"username");
if (username != null) {
if (request.getAttribute("succ") != null) {
%>
<h2>WEB LIST</h2>
<p align="right"><font color="red" size="4">Welcome ${username}</font></p>
<hr>
<%
} else {
%>
<p align="right"><font color="red" size="4">Welcome ${username}</font></p>
<hr>
<%
}
} else {
%>
<jsp:forward page="error.jsp"></jsp:forward>
<%
}
%>
补充:如果head.jsp中是静态文本就没有问题,
来的只是静态文件,那么只是把静态文件的内容加到JSP 网页中;如果包含进来的为动态文件,那
么这个被包含的文件也会被JSP Container 编译执行。