Two uses of include

Two uses of include

The first

<%@include file=""%>

Static inclusion, pre-compiled before page request, all codes are mixed together and compiled into a servlet.

<%@include file="footer.jsp"%>
<%!String userpwd="abc";%>

included file code

<%=userpwd="abc"
%>

The second kind

<jsp:inclue page=“”>

Dynamic inclusion, when executing, only loads the included files for execution. The included files cannot use any code that affects the construction of the main page.

<%@ page contentType="text/html;charset=UTF-8" language="java" errorPage="errorPage.jsp"
%>
<jsp:include page="header.jsp" flush="true">
    <jsp:param name="username" value="lzf"/>
</jsp:include>
<h2>Hello World!</h2>

included file code

<%@ page contentType="text/html;charset=UTF-8" language="java" %>


<img src="./images/1.jpeg" width="1024" height="80"><br>
<a href="">首页</a>
<a href="">国内新闻</a>
<a href="">国际新闻</a>
<a href="">关于我们</a>
<br>
<%=request.getParameter("username")%>

operation result
Insert image description here

Guess you like

Origin blog.csdn.net/lzfaq/article/details/105669528