includeBianyizhiling.jsp:
1 <body> 2 <span class="style1">include 开始</span><br/> 3 <%@ include file="includeBianyizhiling_test.jsp" %><br/> 4 <span class="style1">include 结束</span><br/> 5 </body>
includeBianyizhiling_test.jsp:
1 <% 2 String path2 = request.getContextPath(); 3 String basePath2 = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path2+"/"; 4 %>
1 <body> 2 <table border="1"> 3 <tr> 4 <td> 5 这是第一层include编译指令调用,这个页面同时也测试了scriptlet脚本指令。<br/> 6 <% 7 out.println("定义了一个Scriptlet!"+"<br/>"); 8 String test="This is a test!"; 9 %> 10 <% 11 out.println("使用前面定义的Scriptlet!"+"<br/>"); 12 out.println(test+"<br/>"); 13 String test1 = test.substring(0,4); 14 String test2 = test.substring(5,7); 15 String test3 = test.substring(8,9); 16 String test4 = test.substring(10,14); 17 String test5 = test.substring(14,15); 18 out.println(test1+"<br/>"); 19 out.println(test2+"<br/>"); 20 out.println(test3+"<br/>"); 21 out.println(test4+"<br/>"); 22 out.println(test5+"<br/>"); 23 %> 24 </td> 25 </tr> 26 <tr> 27 <td> 28 <%@ include file="includeBianyizhiling_test2.jsp" %><br/> 29 </td> 30 </tr> 31 </table> 32 </body>
includeBianyizhiling_test2.jsp:
<body> <table border="1" bgcolor="#F0FFFF"> <tr> <td> 这是第二层include编译指令调用,这个页面同时也测试了JSP声明和JSP表达式脚本指令。<br/> </td> </tr> <tr> <td> JSP声明:<br/> <%! // 声明 servlet中的 成员变量和方法 int numTimes=3; public String sayHello(String name){ return "Hello "+name+"!"; } %> <% out.println("每刷新页面一下 numTimes就会累加,这样说明是 员变量 .而且 说明 JSP (servlet) tomcat启动的时候 就只实例化一次 然后被缓存起来了所以 这个变量 就会一直累加<br/>" ); out.println("numTimes = "+numTimes); numTimes++; out.println("<br/>"); out.println(sayHello("admin")); %> </td> </tr> <tr> <td> JSP表达式:<br/> <%=(new java.util.Date()) %> </td> </tr> </table> </body>
运行结果: