Write two documents, one is a JSP document named myJsp.jsp; the other is an ordinary HTML document named myPhoto.html.
Requirements : Insert your own photos in myPhoto.html, embed <jsp:include> operation instructions in myJsp.jsp, and display the photos in myPhoto.html when running in the browser
The code looks like this:
myPhoto.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>myPhoto</title>
</head>
<body>
<image src="b.jpg" alt="照片" width="900px" height="600px">
</image>
</body>
</html>
myJsp.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<jsp:include page="myPhoto.html"></jsp:include>
</body>
</html>
The display results are as follows:
Note : The relative path is used here, and the photo needs to be placed in the same folder as the program
If the topic does not require the <jsp:include> operation command to be written, we can also use the static include command to write, the effect is the same
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%@include file="myPhoto.html"%>
</body>
</html>
Summarize:
- include instruction format: <%@ include file=" " %>
- include action format: <jsp:include page=" "></jsp:include>
The include command is a static link , and the Include action is a dynamic link , both of which can realize the jump including the current page
the difference:
- The variables defined by the include directive are available on this page, but the definition of variables with the same name is not supported. The variables defined by the include action are not available on this page, and the definition of variables with the same name is supported.
- Generally use static
- If two files need to share the same variable, use static
- If there is a variable with the same name, use dynamic
expand:
<jsp:forward page=" "></jsp:forward> Does not contain the current page, jump directly to the embedded page