Ajax + java Servlet 制作Web进度条
2021-03-11 18:28
YPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
标签:ogr ade process ready nal win 操作 timeout put
运行效果图
index2.jsp
Ajax进度条示例 |
|
ProcessServlet2.java
package ajax_servlet_1; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; // https://www.cnblogs.com/lihuiyy/archive/2012/05/24/2516627.html public class ProcessServlet2 extends HttpServlet { private static final long serialVersionUID = 5280356329609002908L; private static final String CONTENT_TYPE = "text/xml; charset=UTF-8"; //设置返回响应的ContentType private int count = 1;// 全局变量计数器 /** *当前Servlet对象构造方法 */ public ProcessServlet2() { super(); } /** *当前Servlet销毁时的操作。
*/ public void destroy() { super.destroy(); } /** *当前Servlet的doGet方法。
* *当客户端表单的“method”类型为“get”时,调用此方法 * * @param request客户端请求对象 * @param response 服务器响应对象 * @throws ServletException 发生ServeltException时抛出 * @throws IOException发生IOException时抛出 */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("*********************doGet()**********"); response.setContentType(CONTENT_TYPE); //设置服务器响应类型 response.setHeader("Cache-Control","no-cache"); //页面不记录缓存 String flag = request.getParameter("flag"); //操作类型 StringBuffer xml= // new StringBuffer(""); new StringBuffer(""); //记录返回的xml串 if("start".equals(flag)) { //第一次创建 // xml.append(" "); PrintWriter out = response.getWriter(); out.println(xml.toString()); //返回生成的XML串 out.flush(); //输出流刷新 out.close(); //关闭输出流 System.out.println("*********** " + xml.toString()); } /** * 初始化servlet.1 "); count = 1; } else { String proportion = ""; try { switch(count) { //根据计数器的值,设置显示当前进度的百分比 case 1: proportion="10"; break; case 2: proportion="20"; break; case 3: proportion="30"; break; case 4: proportion="40"; break; case 5: proportion="50"; break; case 6: proportion="60"; break; case 7: proportion="70"; break; case 8: proportion="80"; break; case 9: proportion="90"; break; case 10: proportion="100"; break; } } catch(InterruptedException e) { e.printStackTrace(); } count++; xml.append("").append(proportion).append(" "); } xml.append("
* @throws ServletException 发生ServletExcpetio异常时抛出 */ public void init() throws ServletException { } }
web.xml
ProcessServlet ajax_servlet_1.ProcessServlet ProcessServlet /ProcessServlet ProcessServlet2 ajax_servlet_1.ProcessServlet2 ProcessServlet2 /ProcessServlet2 index2.jsp
========================================================================================
https://www.cnblogs.com/lihuiyy/archive/2012/05/24/2516627.html
========================================================================================
jqueryProgressBar(jb51.net)
========================================================================================
视频讲解java servlet ajax 进度条
https://www.iqiyi.com/w_19rs93z9rx.html
========================================================================================
Ajax + java Servlet 制作Web进度条
标签:ogr ade process ready nal win 操作 timeout put
原文地址:https://www.cnblogs.com/emanlee/p/14122545.html
上一篇:Spring Boot配置热启动
文章标题:Ajax + java Servlet 制作Web进度条
文章链接:http://soscw.com/index.php/essay/63314.html