欢迎来到福编程网,本站提供各种互联网专业知识!

AJAX 进度条实现代码

发布时间:2009-09-28 作者: 来源:转载
AJAX进度条实现代码,基于java后来,大家可以学习下。
效果如下:

复制代码 代码如下:



Ajax Progress Bar



Ajax Progress Bar Example


Launch long-running process:















复制代码 代码如下:
package cn.Ajax.test;
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;
@SuppressWarnings("serial")
public class ProgressBarServlet extends HttpServlet {
private int counter = 1;
/**
* The doGet method of the servlet.


*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String task = request.getParameter("task");
String res="";
if(task.equals("create")){
res = "1";
counter = 1;
}
else{
String percent = "";
switch (counter) {
case 1: percent = "10";break;
case 2: percent = "23";break;
case 3: percent = "35";break;
case 4: percent = "51";break;
case 5: percent = "64";break;
case 6: percent = "73";break;
case 7: percent = "89";break;
case 8: percent = "100";break;
}
counter++;
res =""+percent+"";
}
PrintWriter out = response.getWriter();
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
out.println("");
out.println(res);
out.println("
");
out.close();
}
/**
* The doPost method of the servlet.


*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}

相关推荐