- 浏览: 188944 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
duguyiren3476:
我现在的版本是drill0.8.0版本的,搭建了分布式4个节点 ...
walter的drill笔试之二-安装与部署 -
zhangth:
写的不错,受教了
图片分离之图片服务器问题 -
lt200819:
zh55com 写道如何查询mysql数据?如何查询hbase ...
walter的drill笔试之二-安装与部署 -
zh55com:
如何查询mysql数据?如何查询hbase数据?
walter的drill笔试之二-安装与部署 -
QuarterLifeForJava:
不错,挺好的,那如果是update、delete、insert ...
Mysql百万级数据查询优化
<%@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=\"background-color:lightblue\">\r\n");
out.write("\r\n");
out.write("\t\t");
<span style="color:#ff0000;">org.apache.jasper.runtime.JspRuntimeLibrary.include(request,response, "header.html", out, true);</span>
out.write("<!--动态包含-->\r\n");
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>");
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=\"background-color:lightblue\">\r\n"); out.write("\r\n"); out.write("\t\t"); <span style="color:#ff0000;">org.apache.jasper.runtime.JspRuntimeLibrary.include(request,response, "header.html", out, true);</span> out.write("<!--动态包含-->\r\n"); 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>");
第二种情况(<jsp:include>包含的是jsp文件):
DynamicInclude.jsp:
[html]
<%@pagecontentType="text/html;charset=gb2312"%>
<html>
<head>
<title>动态包含</title>
</head>
<bodystylebodystyle="background-color:lightblue">
<jsp:include page="header.jsp"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.jsp"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.jsp :
[html]
<%@pagecontentType="text/html;charset=gb2312"%>
<html>
<body>
<h2styleh2style="font-family:arial;color:red;font-size:25px;text-align:center">
动态包含的标题(JSP)
</h2>
</body>
</html>
<%@pagecontentType="text/html;charset=gb2312"%> <html> <body> <h2style="font-family:arial;color:red;font-size:25px;text-align:center"> 动态包含的标题(JSP) </h2> </body> </html>
运行之后,生成了两个servlet:DynamicInclude_jsp.java和header_jsp.java,这也是为什么 Header.jsp中要写上<%@page contentType="text/html;charset=gb2312"%>和完整的<html></html>和<body></body>,而Header.html不用写的原因。因为前者两个.jsp文件是两个相互独立的整体,它们之间的关系是通过request和reponse来发生的,而后者只是简单的嵌套。两个servlet对应的代码如下:
DynamicInclude_jsp.java:
[html]
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<bodystylebodystyle=\"background-color:lightblue\">\r\n");
out.write("\r\n");
out.write("\t\t");
<span style="color:#ff0000;">org.apache.jasper.runtime.JspRuntimeLibrary.include(request,response, "header.jsp", out, true);</span>
out.write("<!--动态包含-->\r\n");
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>");
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=\"background-color:lightblue\">\r\n"); out.write("\r\n"); out.write("\t\t"); <span style="color:#ff0000;">org.apache.jasper.runtime.JspRuntimeLibrary.include(request,response, "header.jsp", out, true);</span> out.write("<!--动态包含-->\r\n"); 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>");
header_jsp.java:
[html]
out.write("\r\n");
out.write("<html>\r\n");
out.write("\t<body>\r\n");
out.write("\t\t<h2 style=\"font-family:arial;color:red;font-size:25px;text-align:center\">\r\n");
out.write("\t\t\t动态包含的标题(JSP)\r\n");
out.write("\t\t</h2>\r\n");
out.write("\t</body>\r\n");
out.write("</html>");
out.write("\r\n"); out.write("<html>\r\n"); out.write("\t<body>\r\n"); out.write("\t\t<h2 style=\"font-family:arial;color:red;font-size:25px;text-align:center\">\r\n"); out.write("\t\t\t动态包含的标题(JSP)\r\n"); out.write("\t\t</h2>\r\n"); out.write("\t</body>\r\n"); out.write("</html>");
<%@include%>:静态包含
第一种情况:<%@include%>包含的是jsp文件。
StaticInclude.jsp:
[html]
<%@pagecontentType="text/html;charset=gb2312"%>
<html>
<head>
<title>静态包含</title>
</head>
<bodystylebodystyle="background-color:lightblue">
<%@include file="header.jsp"%><!--静态包含-->
<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"> <%@include file="header.jsp"%><!--静态包含--> <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.jsp:
[html]
<%@pagecontentType="text/html;charset=gb2312"%>
<h2styleh2style="font-family:arial;color:red;font-size:25px;text-align:center">
静态包含的标题(JSP)
</h2>
<%@pagecontentType="text/html;charset=gb2312"%> <h2style="font-family:arial;color:red;font-size:25px;text-align:center"> 静态包含的标题(JSP) </h2>
运行之后,只生成一个servlet,和上面的代码对应如下:
[html]
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("<h2styleh2style=\"font-family:arial;color:red;font-size:25px;text-align:center\">\r\n");
out.write("\t静态包含的标题(JSP)\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>");
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("<h2style=\"font-family:arial;color:red;font-size:25px;text-align:center\">\r\n"); out.write("\t静态包含的标题(JSP)\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文件。
StaticInclude.jsp:
[html]
<%@pagecontentType="text/html;charset=gb2312"%>
<html>
<head>
<title>静态包含</title>
</head>
<bodystylebodystyle="background-color:lightblue">
<%@include file="header.html"%><!--静态包含-->
<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"> <%@include file="header.html"%><!--静态包含--> <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]
<%@pagecontentType="text/html;charset=gb2312"%>
<h2styleh2style="font-family:arial;color:red;font-size:25px;text-align:center">
静态包含的标题(HTML)
</h2>
<%@pagecontentType="text/html;charset=gb2312"%> <h2style="font-family:arial;color:red;font-size:25px;text-align:center"> 静态包含的标题(HTML) </h2>
运行之后,也是只生成一个servlet,和上面的代码对应如下:
[html]
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<bodystylebodystyle=\"background-color:lightblue\">\r\n");
out.write("\r\n");
out.write("\t\t");
out.write("\r\n");
<span style="color:#ff0000;">out.write("<h2styleh2style=\"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>");
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=\"background-color:lightblue\">\r\n"); out.write("\r\n"); out.write("\t\t"); out.write("\r\n"); <span style="color:#ff0000;">out.write("<h2style=\"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%>,中包含的文件,只是简单的嵌入到主文件中,就是在jsp页面转化成Servlet时才嵌入到主文件中,因为运行的结果是只生成了一个Servlet。
而对于动态包含<jsp:incude>,如果被包含文件是动态的,那么就会生成两个Servlet,也就是被包含文件也要经过jsp引擎编译执行生成一个Servlet,两个Servlet通过request和reponse进行通信。如果被包含的文件是静态的,那么这种情况和<%@include>就很相似,只生成了一个Servlet,但是他们之间没有进行简单的嵌入,而依然是通过request和reponse进行的通信。
<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=\"background-color:lightblue\">\r\n");
out.write("\r\n");
out.write("\t\t");
<span style="color:#ff0000;">org.apache.jasper.runtime.JspRuntimeLibrary.include(request,response, "header.html", out, true);</span>
out.write("<!--动态包含-->\r\n");
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>");
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=\"background-color:lightblue\">\r\n"); out.write("\r\n"); out.write("\t\t"); <span style="color:#ff0000;">org.apache.jasper.runtime.JspRuntimeLibrary.include(request,response, "header.html", out, true);</span> out.write("<!--动态包含-->\r\n"); 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>");
第二种情况(<jsp:include>包含的是jsp文件):
DynamicInclude.jsp:
[html]
<%@pagecontentType="text/html;charset=gb2312"%>
<html>
<head>
<title>动态包含</title>
</head>
<bodystylebodystyle="background-color:lightblue">
<jsp:include page="header.jsp"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.jsp"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.jsp :
[html]
<%@pagecontentType="text/html;charset=gb2312"%>
<html>
<body>
<h2styleh2style="font-family:arial;color:red;font-size:25px;text-align:center">
动态包含的标题(JSP)
</h2>
</body>
</html>
<%@pagecontentType="text/html;charset=gb2312"%> <html> <body> <h2style="font-family:arial;color:red;font-size:25px;text-align:center"> 动态包含的标题(JSP) </h2> </body> </html>
运行之后,生成了两个servlet:DynamicInclude_jsp.java和header_jsp.java,这也是为什么 Header.jsp中要写上<%@page contentType="text/html;charset=gb2312"%>和完整的<html></html>和<body></body>,而Header.html不用写的原因。因为前者两个.jsp文件是两个相互独立的整体,它们之间的关系是通过request和reponse来发生的,而后者只是简单的嵌套。两个servlet对应的代码如下:
DynamicInclude_jsp.java:
[html]
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<bodystylebodystyle=\"background-color:lightblue\">\r\n");
out.write("\r\n");
out.write("\t\t");
<span style="color:#ff0000;">org.apache.jasper.runtime.JspRuntimeLibrary.include(request,response, "header.jsp", out, true);</span>
out.write("<!--动态包含-->\r\n");
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>");
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=\"background-color:lightblue\">\r\n"); out.write("\r\n"); out.write("\t\t"); <span style="color:#ff0000;">org.apache.jasper.runtime.JspRuntimeLibrary.include(request,response, "header.jsp", out, true);</span> out.write("<!--动态包含-->\r\n"); 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>");
header_jsp.java:
[html]
out.write("\r\n");
out.write("<html>\r\n");
out.write("\t<body>\r\n");
out.write("\t\t<h2 style=\"font-family:arial;color:red;font-size:25px;text-align:center\">\r\n");
out.write("\t\t\t动态包含的标题(JSP)\r\n");
out.write("\t\t</h2>\r\n");
out.write("\t</body>\r\n");
out.write("</html>");
out.write("\r\n"); out.write("<html>\r\n"); out.write("\t<body>\r\n"); out.write("\t\t<h2 style=\"font-family:arial;color:red;font-size:25px;text-align:center\">\r\n"); out.write("\t\t\t动态包含的标题(JSP)\r\n"); out.write("\t\t</h2>\r\n"); out.write("\t</body>\r\n"); out.write("</html>");
<%@include%>:静态包含
第一种情况:<%@include%>包含的是jsp文件。
StaticInclude.jsp:
[html]
<%@pagecontentType="text/html;charset=gb2312"%>
<html>
<head>
<title>静态包含</title>
</head>
<bodystylebodystyle="background-color:lightblue">
<%@include file="header.jsp"%><!--静态包含-->
<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"> <%@include file="header.jsp"%><!--静态包含--> <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.jsp:
[html]
<%@pagecontentType="text/html;charset=gb2312"%>
<h2styleh2style="font-family:arial;color:red;font-size:25px;text-align:center">
静态包含的标题(JSP)
</h2>
<%@pagecontentType="text/html;charset=gb2312"%> <h2style="font-family:arial;color:red;font-size:25px;text-align:center"> 静态包含的标题(JSP) </h2>
运行之后,只生成一个servlet,和上面的代码对应如下:
[html]
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("<h2styleh2style=\"font-family:arial;color:red;font-size:25px;text-align:center\">\r\n");
out.write("\t静态包含的标题(JSP)\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>");
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("<h2style=\"font-family:arial;color:red;font-size:25px;text-align:center\">\r\n"); out.write("\t静态包含的标题(JSP)\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文件。
StaticInclude.jsp:
[html]
<%@pagecontentType="text/html;charset=gb2312"%>
<html>
<head>
<title>静态包含</title>
</head>
<bodystylebodystyle="background-color:lightblue">
<%@include file="header.html"%><!--静态包含-->
<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"> <%@include file="header.html"%><!--静态包含--> <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]
<%@pagecontentType="text/html;charset=gb2312"%>
<h2styleh2style="font-family:arial;color:red;font-size:25px;text-align:center">
静态包含的标题(HTML)
</h2>
<%@pagecontentType="text/html;charset=gb2312"%> <h2style="font-family:arial;color:red;font-size:25px;text-align:center"> 静态包含的标题(HTML) </h2>
运行之后,也是只生成一个servlet,和上面的代码对应如下:
[html]
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<bodystylebodystyle=\"background-color:lightblue\">\r\n");
out.write("\r\n");
out.write("\t\t");
out.write("\r\n");
<span style="color:#ff0000;">out.write("<h2styleh2style=\"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>");
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=\"background-color:lightblue\">\r\n"); out.write("\r\n"); out.write("\t\t"); out.write("\r\n"); <span style="color:#ff0000;">out.write("<h2style=\"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%>,中包含的文件,只是简单的嵌入到主文件中,就是在jsp页面转化成Servlet时才嵌入到主文件中,因为运行的结果是只生成了一个Servlet。
而对于动态包含<jsp:incude>,如果被包含文件是动态的,那么就会生成两个Servlet,也就是被包含文件也要经过jsp引擎编译执行生成一个Servlet,两个Servlet通过request和reponse进行通信。如果被包含的文件是静态的,那么这种情况和<%@include>就很相似,只生成了一个Servlet,但是他们之间没有进行简单的嵌入,而依然是通过request和reponse进行的通信。
发表评论
-
jsp velocity freemarker 比较
2013-09-06 10:57 735jsp是大家最熟悉的技术 优点: 1、功能强大,可以写jav ... -
HTTP协议详解
2013-08-20 11:57 782引言 ... -
RESTFul以及实现
2013-08-20 11:42 782什么是REST? REST (REpresentatio ... -
spring security3.1开发样例
2013-07-13 15:33 966Spring Security3的使用方法有4种: ... -
springMVC和struts2的比较
2013-07-07 18:41 10861:spring3 mvc开发效率高于struts 2: ... -
mybatis与hibernate比较
2013-07-07 14:57 1082最近做了一个Hibernate ... -
mybatis生成工具MyBatis Generator
2013-06-19 10:28 1297eclipse插件安装地址:http://mybatis. ... -
nginx
2013-05-06 17:37 780Nginx ("engine ... -
REST架构
2013-05-06 17:00 732REST架构风格是全新的针对Web应用的开发风格,是当今世 ... -
webservice
2013-03-28 11:20 909现在webservice加xml技术已经逐渐成熟,但要真正 ... -
frame,iframe,frameset之间的关系与区别
2013-01-02 14:03 908原文出处:http://www.cnblogs.com ... -
JPA2.0 条件查询
2012-10-10 21:05 1395Java代码 packag ... -
灵活控制 Hibernate 的日志或 SQL 输出,以便于诊断
2012-08-18 15:03 1248我们在使用 Hibernate 时一般只会关注是否显示生 ... -
jsp编码格式问题
2012-05-23 16:20 10821 所有的 .java|.jsp|.html|.xml 源文件 ... -
图片分离之图片服务器问题
2012-02-17 22:09 1391现在很多中小网站(尤其是 Web 2.0 站点) 都允许用户上 ... -
坑爹的JPA
2011-11-24 17:48 853order是数据库的固有表格,不能新建order表; memb ... -
修改网站的小图标
2011-11-23 22:02 832通过查看你的源代码发现。 您的设置有问题: <link ... -
jpa得到JDBC的connection
2011-11-23 19:21 2099JPA 2.0 entityManager.getTransa ... -
原样输出HTML
2011-11-21 20:21 1120<textarea></textarea&g ... -
JPA查询语句
2011-11-14 15:03 21921.查询所有信息 Query q = em.createQu ...
相关推荐
在JavaServer Pages (JSP) 技术中,`<jsp:include>` 和 `<%@ include %>` 是两个用于页面组合的指令,它们虽然都用于将一个或多个文件的内容插入到主页面中,但它们的工作机制和使用场景有所不同。理解这两者的区别...
5. **JSP动作标签**:除了`<%@ %>`,还有 `<jsp:include>`, `<jsp:forward>`, `<jsp:params>` 等JSP动作标签,它们用于处理页面间的跳转、包含和参数传递。 6. **EL(Expression Language)**:EL是JSP 2.0引入的一...
查询到如下记录:<BR> <% StringBuffer b=book.getMessageBybook_id(); %> <%=b%> <P>如果准备订购该书,请填写订单,点击"添加到订单"按钮<BR> <%if((book.getId())!=0) {%> <FORM action="<%=str%>" method=...
5. **动作元素**(Action):用于插入动态内容或引用外部资源,如`<jsp:include>`、`<jsp:param>`等。 #### 四、JSP的优点 1. **跨平台性**:由于Java本身具有良好的跨平台特性,因此基于JSP的应用程序可以在多种...
JSP 中的 Include 有两种用法,分别是 `<%@ include file=” ”%>` 和 `<jsp:include page=” ” flush=”true”/>`。这两种用法都可以用于引入其他 JSP 文件,但是它们之间存在着一些关键的区别。 首先,让我们...
<%-- 或者使用静态包含:<%@ include file="date.jsp" %> --%> </head> <body> <p>今天的日期是:</p> </body> </html> ``` 如果使用`<jsp:include page="date.jsp" flush="true"/>`,那么每当访问`test.jsp...
nt test</title></head><body>This content is statically in the main JSP file.<br/><jsp:include page="included.html"/></body></html>]]>)正如你所见,清单2使用了传统的`<%@include file="..."%>`伪指令来包含...
考虑下面JSP文件代码片断: ...<jsp:include page=”test2.jsp”> <jsp:param name=”username” value=”accp”/> </jsp:include> </BODY> </HTML> 以下( )代码片断放置在test2.jsp中不会导致错误。
<td height="277" align="center" valign="top"><%@include file="changxiao.jsp"%></td> </tr> </table> <br> <table width="208" height="356" border="0" cellpadding="0" cellspacing="0" background=...
<tr><td colspan="2"><jsp:include page="view/AdminTop.jsp" /></td></tr> <tr bgcolor="#F0EAED"> <td width="180" valign="top"><jsp:include page="view/AdminLeft.jsp"/></td> <td width="598" align=...
`<%@ include %>` 指令是 JSP 提供的一种机制,用于将一个文件插入到另一个文件中。这种方式主要用于重用代码块,例如页面头部、底部等。 ##### 语法 ```jsp <%@ include file="relativeURLspec" %> ``` 这里的 `...
动作语法包括<jsp:forward>、<jsp:include>、<jsp:plugin>、<jsp:getProperty> 和 <jsp:setProperty> 等。 在 JSP 语法中,声明用于在页面上输出信息,语法格式如下:<%! declaration; [ declaration; ] ... %> 或 ...
标准动作元素是JSP提供的一些基本动作元素,例如<jsp:include>、<jsp:param>、<jsp:forward>、<jsp:useBean>、<jsp:getProperty>、<jsp:setProperty>和<jsp:plugin>等。自定义动作元素是开发者根据需求自定义的动作...
<jsp:include page="footer.jsp"> <jsp:param name="message" value="欢迎访问!"/> </jsp:include> </body> </html> ``` ### 主要标签 JSP还支持使用自定义标签库,比如JSTL(JavaServer Pages Standard Tag ...
- **动作元素**:用于调用JSP组件,如`<jsp:include>`, `<jsp:forward>`, `<jsp:param>`等。 **3. 注释** 在JSP中,可以使用HTML注释(`<!-- ... -->`)或Java注释(`//`, `/* ... */`)。Java注释在JSP被翻译成...
<p>当前时间:<%= currentTime %></p> ``` 在这个示例中,我们首先创建了一个`Date`对象来获取当前日期时间,然后使用`SimpleDateFormat`类格式化时间字符串,最后通过`<%= currentTime %>`输出到页面上。 #### 4....
1. **JSP指令**:JSP提供了三种类型的指令,包括`<%@ page %>`, `<%@ include %>`, 和`<jsp:forward>`。`<%@ page %>`用来设置整个页面的属性,如编码、错误页面等;`<%@ include %>`用于在运行时将一个文件包含到...