日期:2014-05-16  浏览次数:20357 次

<%@include%>和<jsp:include>的区别
<%@include%>和<jsp:include>的区别

<jsp:include> :动态包含

第一种情况(<jsp:include>包含的是html文件):

DynamicInclude.jsp:

[html]
<%@pagecontentType="text/html;charset=gb2312"%> 
<html> 
         <head> 
                   <title>动态包含</title> 
         </head> 
         <bodystylebodystyle="background-color:lightblue"> 
  
                   <jsp:include page="header.html"flush="true"/><!--动态包含--> 
  
                   <tablebordertableborder="1" align="center"> 
                            <tr> 
                                     <td>姓名</td><td>性别</td><td>年龄</td><td>爱好</td> 
                            </tr> 
                            <tr> 
                                     <td>a</td><td>b</td><td>c</td><td>d</td> 
                            </tr> 
                   </table> 
         </body> 
</html> 
<%@pagecontentType="text/html;charset=gb2312"%> <html> <head> <title>动态包含</title> </head> <bodystyle="background-color:lightblue"> <jsp:include page="header.html"flush="true"/><!--动态包含--> <tableborder="1" align="center"> <tr> <td>姓名</td><td>性别</td><td>年龄</td><td>爱好</td> </tr> <tr> <td>a</td><td>b</td><td>c</td><td>d</td> </tr> </table> </body> </html>


Header.html :

[html]
<h2styleh2style="font-family:arial;color:red;font-size:25px;text-align:center"> 
         动态包含的标题(HTML) 
</h2> 
<h2style="font-family:arial;color:red;font-size:25px;text-align:center"> 动态包含的标题(HTML) </h2>
运行之后,只生成一个servlet,和上面的代码对应如下:

[java]
out.write("\r\n"); 
out.write("<html>\r\n"); 
out.write("\t<head>\r\n"); 
out.write("\t\t<title>动态包含</title>\r\n"); 
out.write("\t</head>\r\n"); 
out.write("\t<bodystyle=\"backgroun