1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib prefix="b" uri="/WEB-INF/bigpipe.tld"%> <%long pstart = System.currentTimeMillis();%> <table border="1" width="100%" height="500"> <caption> 单线程例子 </caption> <tr> <td><b:bigPipeTo name="index1"> 编号:1 <img src="images/loading.gif"/></b:bigPipeTo></td> <td><b:bigPipeTo name="index2"> 编号:2 <img src="images/loading.gif"/></b:bigPipeTo></td> <td><b:bigPipeTo name="index3"> 编号:3 <img src="images/loading.gif"/></b:bigPipeTo></td> </tr> <tr> <td><b:bigPipeTo name="index4"> 编号:4 <img src="images/loading.gif"/></b:bigPipeTo></td> <td><b:bigPipeTo name="index5"> 编号:5 <img src="images/loading.gif"/></b:bigPipeTo></td> <td><b:bigPipeTo name="index6"> 编号:6 <img src="images/loading.gif"/></b:bigPipeTo></td> </tr> </table> <b:bigPipeFrom name="index6" bigPipeJSPath="js/bigpipe.js"> <% long start = System.currentTimeMillis(); Thread.sleep(6000); long seconds = System.currentTimeMillis() - start; %> 6 秒的内容 <br> 加载耗时:<%=seconds%> 毫秒 ; </b:bigPipeFrom> // 中间的 4 个由于篇幅限制,省略… <b:bigPipeFrom name="index1" bigPipeJSPath="js/bigpipe.js"> <% long start = System.currentTimeMillis(); Thread.sleep(1000); long seconds = System.currentTimeMillis() - start; %> 1 秒的内容 <br> 加载耗时:<%=seconds%> 毫秒 ; </b:bigPipeFrom> … |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | @Override public boolean start(final Writer writer) { boolean result = super.start(writer); try { writer.flush();// 刷新显示网页结构 // 用 DIV 包围内容 if (visiable) { writer.write("<div style='display:none' id='" + name + "_from'>"); } else { writer.write("<div id='" + name + "_from'>"); } } catch (IOException e) { e.printStackTrace(); } return result; } @Override public boolean end(Writer writer, String body) { boolean end = super.end(writer, body); try { //DIV 的结束,也就是该标签里的内容加载完毕 writer.write("</div>"); // 引入移动内容的 JavaScript 文件,就是 <script src=”…”></script> BigPipeWriter.instance().writeJavaScript(bigPipeJSPath, writer); // 调用 moveContent 方法的脚本代码 BigPipeWriter.instance().writeFromToTo(name, writer, copy); } catch (Exception e) { e.printStackTrace(); } return end; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public boolean start(final Writer writer) { boolean result = super.start(writer); try { writer.write("<div id='"+name+"'>"); } catch (IOException e) { e.printStackTrace(); } return result; } @Override public boolean end(Writer writer, String body) { boolean end = super.end(writer, body); try { writer.write("</div>"); } catch (IOException e) { e.printStackTrace(); } return end; } |
1 2 3 4 5 | function moveContent(fromId, toId) { document.getElementById(toId).innerHTML = document.getElementById(fromId).innerHTML; document.getElementById(fromId).innerHTML = ""; } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |