FileUploading.java
上传用户:u_thks
上传日期:2022-07-31
资源大小:1910k
文件大小:3k
- /*
- * Made In GamVan
- */
- package com.gamvan.fileUpload;
- 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;
- import javax.servlet.http.HttpSession;
- import com.gamvan.tools.Arith;
- import com.gamvan.tools.TypeChange;
- public class FileUploading extends HttpServlet {
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- protected void service(HttpServletRequest req, HttpServletResponse rep) throws ServletException, IOException {
-
- rep.setCharacterEncoding("UTF-8");
- rep.setContentType("text/html");
- PrintWriter out = rep.getWriter();
- out.print("<html><head><title>上传进度条 powered by GamVan.com</title>");
- out.print("<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">");
- out.print("</head>");
-
- HttpSession session = req.getSession();
- String str = String.valueOf(session.getAttribute("fileSize"));
- String str1 = String.valueOf(session.getAttribute("readsBytes"));
- long fileSize = TypeChange.stringToLong(str);
- long readsBytes = TypeChange.stringToLong(str1);
- int i = 0; //上传进度
- double d = TypeChange.longToDouble(fileSize);
- double d2 = TypeChange.longToDouble(readsBytes);
- i = TypeChange.doubleToInt(Arith.div(d2,d,2)*100);
- int imgWidth = 0;
- imgWidth = (i*3);
-
- if(fileSize==readsBytes && readsBytes>0){
- session.removeAttribute("fileSize");
- session.removeAttribute("readsBytes");
- str = "上传完毕";
- str1 = "上传完毕";
- }else{
- rep.setHeader("Refresh", "2");
- }
-
- StringBuffer sb = new StringBuffer();
- sb.append("<script language="javascript">n");
- sb.append("function loading(){n");
-
- sb.append("if(!parent.document.layers&&!parent.document.all){n");
- sb.append("return;n");
- sb.append("}n");
-
- sb.append("if(document.layers){n");
- sb.append("parent.document.layers.fileSize.document.write(""+ str +"");n");
- sb.append("parent.document.layers.readsBytes.document.write(""+ str1 +"");n");
- sb.append("parent.document.layers.readSchedule.document.write(""+ i +"%");n");
- sb.append("parent.document.images.imgLoading.width="+imgWidth+"");
- sb.append("}else if(document.all){n");
- sb.append("parent.fileSize.innerHTML=""+ str +"";n");
- sb.append("parent.readsBytes.innerHTML=""+ str1 +"";n");
- sb.append("parent.readSchedule.innerHTML=""+ i +"%";n");
- sb.append("parent.imgLoading.width="+imgWidth+"");
-
- sb.append("}n");
- sb.append("}n");
- sb.append("</script>");
- out.print(sb.toString());
- out.print("<body onload="loading();">");
- out.print("</body></html>");
- out.close();
- }
-
-
- }