JSP include如何包含html页面
include包含html页面实例如下:
header.html
<%@page contentType="text/html;charset=gb2312"%> <h2 style="font-family:arial;color:red;font-size:25px;text-align:center"> 静态包含的标题(HTML) </h2>
StaticInclude.jsp
<%@page contentType="text/html;charset=gb2312"%> <html> <head> <title>静态包含</title> </head> <body style="background-color:lightblue"> <%@include file="header.html"%><!--静态包含--> <table border="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>
运行之后生成一个servlet
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<body style=\"background-color:lightblue\">\r\n"); out.write("\r\n"); out.write("\t\t"); out.write("\r\n"); <span style="color:#ff0000;">out.write("<h2 style=\"font-family:arial;color:red;font-size:25px;text-align:center\">\r\n"); out.write("\t静态包含的标题(HTML)\r\n"); out.write("</h2>");</span> out.write("<!--静态包含-->\r\n"); out.write("\t\t<table border=\"1\"align=\"center\">\r\n"); out.write("\t\t\t<tr>\r\n"); out.write("\t\t\t\t<td>姓名</td><td>性别</td><td>年龄</td><td>爱好</td>\r\n"); out.write("\t\t\t</tr>\r\n"); out.write("\t\t\t<tr>\r\n"); out.write("\t\t\t\t<td>a</td><td>b</td><td>c</td><td>d</td>\r\n"); out.write("\t\t\t</tr>\r\n"); out.write("\t\t</table>\r\n"); out.write("\t</body>\r\n"); out.write("</html>");
对于静态包含<%@include%>中包含的文件(比如html,jsp等),只是简单的嵌入到主文件中,就是在jsp页面转化成Servlet时才嵌入到主文件中,因为运行的结果是只生成了一个Servlet。
版权声明:本文为JAVASCHOOL原创文章,未经本站允许不得转载。