java代码007

code007.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>包含文件标识</title>
</head>
<body>

    <%--
        jsp:inclue page="url" flush="false|true" 
        page:用于指定被包含文件的相对路径。
        flush:可选属性,用于是否刷新缓冲区。默认值为false,
        如果为true,当前页面输出使用了缓冲区,先刷新缓冲区,
        再执行包含工作。
     --%>

     <%--
     举例
     新建一个top.jsp文件,内容如下:
     <img src="images/banner.jpg">

     新建一个copyright.jsp文件,内容如下:
     %
     String copyright = "&nbsp;All Copyright &copy;某某公司";
     %
     <table>
         <tr>
             <td> %= copyright% </td>
         </tr>
     </table>

     新建一个index.jsp的文件,内容如下:
     body
     jsp:include page="top.jsp" 
     <table>
         <tr>
             <td>&nbsp;</td>
         </tr>
     </table>
     jsp:inclue page="copyright.jsp 
     /body

     前面的代码中,我们学习到include指令,该指令与jsp:include
     动作标识相同,都是可以包含文件的。但是它们存在差别,

     1.include指令通过file属性指定被包含的文件,file属性不支持任何
     表达式;jsp:include动作标识通过page 属性指定被包含的文件,支持
     JSP表达式。

     2.使用include指令时,被包含文件的内容会原封不动的插入包含页中,
     然后JSP编译器再将合成的文件编译成一个java文件;jsp:include动作
     标识包含文件时,当执行该标识时,程序会将请求转发,注意是转发,不是
     请求重定向,到被包含的页面,并将结果输出到浏览器中。编译器会对这些
     文件分别编译。

     3.在include指令包含文件时,被包含文件和包含文件中不能有重名
     的变量或方法;而jsp:include动作标识,每个文件单独编译,所以
     被包含的文件和包含文件中的重名的变量方法不冲突。


      --%>
</body>
</html>

评论

h
hw_7864

⭐️ Admin快速开发: https://show.cool-admin.com/

赞 0
h
hw_7864

⭐️ 官方文档: https://cool-js.com

赞 0
h
hw_7864

⭐️ chatgpt在线体验: https://cool-js.com/ai/chat-vip/index.html?r=helloworld

赞 0