望各位大人帮我解惑 小女子感激不尽
JSP中动态INCLUDE与静态INCLUDE的区别?
答:动态INCLUDE用jsp:include动作实现 它总是会检查所含文件中的变化静态INCLUDE用include伪码实现,定不会检查所含文件的变化
甚么叫 检测变化啊
[此贴子已经被作者于2007-5-23 21:41:11编辑过]
----------------解决方案--------------------------------------------------------
我自己写了一个测试 发现它都会变化啊
我用Myjsp分别动态调用Myjsp1和静态调用MyJsp2 当我刷新Myjsp的时候时间都会变啊 那还有甚么动态静态之说呢???
想不明白啊
=====MyJsp.jsp======
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>Time change</title>
</head>
<body>
<%@ include file="MyJsp2.jsp" %>
<jsp:include flush="true" page="MyJsp1.jsp"></jsp:include>
</body>
</html>
==============MyJsp1.jsp=====
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<%
long time = System.currentTimeMillis();
%>
<%=time %>
</body>
</html>
=========MyJsp2.jsp======
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<body>
<%
long time = System.currentTimeMillis();
%>
<%=time %>
</body>
</html>
----------------解决方案--------------------------------------------------------
检查所含文件中的变化
它这个文件中的变化指的是甚么啊 甚么叫文件中的变化啊
----------------解决方案--------------------------------------------------------
你看看这个就明白了http://blog.sina.com.cn/u/5896bbcd010005qw
解释的很清楚
----------------解决方案--------------------------------------------------------
文件中的变化,就是你的文件内容的变化
比如你把JSP2里面的long time = System.currentTimeMillis();改为long time=123456L;
包含 它的MYJSP就不会更新了,依然是执行long time = System.currentTimeMillis();
----------------解决方案--------------------------------------------------------
简单的说,动态的INCLUDE每次打开页面前都会重新检测被包含页面的内容是否有改动,并重新生成页面.
而静态的INCLUDE除非你清除缓存或重启服务器,否则不会重新生成新页面.
----------------解决方案--------------------------------------------------------
文件中的变化,就是你的文件内容的变化
比如你把JSP2里面的long time = System.currentTimeMillis();改为long time=123456L;
包含 它的MYJSP就不会更新了,依然是执行long time = System.currentTimeMillis();
我试了会变化啊
----------------解决方案--------------------------------------------------------
我把它改成这样它为什么也没问题 我觉得是不是应该报个<%@ page contentType="text/html;charset=UTF-8" %>重复的异常啊!但是运行甚么问题也没有 郁闷啊 搞不明白啊
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<title>Time change</title>
</head>
<body>
<%@ include file="MyJsp2.jsp" %>
</body>
</html>
======MyJsp2。jsp===
<%@ page contentType="text/html;charset=UTF-8" %>
<%
long time = System.currentTimeMillis();
%>
<%=time %>
----------------解决方案--------------------------------------------------------
package org.apache.jsp;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
public final class MyJsp_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {
private static java.util.List _jspx_dependants;
static {
_jspx_dependants = new java.util.ArrayList(1);
_jspx_dependants.add("/MyJsp2.jsp");
}
public Object getDependants() {
return _jspx_dependants;
}
public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException {
JspFactory _jspxFactory = null;
PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
JspWriter _jspx_out = null;
PageContext _jspx_page_context = null;
try {
_jspxFactory = JspFactory.getDefaultFactory();
response.setContentType("text/html;charset=UTF-8");
pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;
out.write("\r\n");
out.write("<html>\r\n");
out.write(" <head>\r\n");
out.write(" <title>Time change</title>\r\n");
out.write(" </head>\r\n");
out.write(" <body>\r\n");
out.write(" ");
out.write("\r\n");
out.write(" ");
long time = System.currentTimeMillis();
out.write("\r\n");
out.write(" ");
out.print(time );
out.write("\r\n");
out.write(" ");
out.write("\r\n");
out.write(" ");
out.write("\r\n");
out.write(" </body>\r\n");
out.write("</html>\r\n");
} catch (Throwable t) {
if (!(t instanceof SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
out.clearBuffer();
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
}
} finally {
if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
}
}
}
所生成的servlet 为什么不是两个response.setContentType("text/html;charset=UTF-8");它不是静态包含吗?
----------------解决方案--------------------------------------------------------
JAVA也不至于傻到这种 地步吧
----------------解决方案--------------------------------------------------------