进度条的问题

问题描述

最近做一个导入进度条的功能,不是上传文件,是execl导入里面每条每行的数据,用jdbc和servlet在做,本来用ajax做的,而且我还要把插入失败的信息和你一共插入了多少行,还有进度条一起展示在一个页面上,而且用ajax做进度条要循环调用自己的函数,才能循环在后台得到jdbcdao层的影响行数,这样又跟我servlet导入有冲突,请问怎么解决这个疑难杂症。

解决方案

解决方案二:
jsp的代码

<%@pagelanguage="java"import="java.util.*"pageEncoding="gbk"%><%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><basehref="<%=basePath%>"><title>MyJSP'execlload.jsp'startingpage</title><metahttp-equiv="pragma"content="no-cache"><metahttp-equiv="cache-control"content="no-cache"><metahttp-equiv="expires"content="0"><metahttp-equiv="keywords"content="keyword1,keyword2,keyword3"><metahttp-equiv="description"content="Thisismypage"><scriptsrc="js/prototype.js"type="text/javascript"></script><!--<linkrel="stylesheet"type="text/css"href="styles.css">--><scripttype="text/javascript">functiongetValueIE8(id){varip=document.getElementById(id);ip.select();varfoo1=document.selection.createRange().text;varmyAjax=newAjax.Request('ajaxServlet/insertcustomers.do?filename='+encodeURIComponent(foo1),{method:'post',parameters:Form.serialize('form1'),evalScripts:true,onComplete:reportError});}functionreportError(originalRequest){varmyobj=originalRequest.responseText.evalJSON(true);varstr="<table>";str=str+"<trstyle='color:red'>";str=str+"<td>以下数据导入失败,请重清空execl数据,重新导入<td><br/>";str=str+"</tr>"myobj.each(function(myobj1){str=str+"<trstyle='color:red'>";str=str+"<td>"+myobj1+"<td><br/>";str=str+"</tr>";});str=str+"</table>";$("reportError").innerHTML=str;}</script></head><body><formname="form1"id="form1"><inputtype="file"name="foo"id="foo"/><inputtype="button"value="execl导入"onclick="getValueIE8('foo')"/><inputtype="hidden"id="percent"value="0"size="2"><divid="reportError"></div></form></body></html>
解决方案三:
servlet代码publicvoidinsertExecl(HttpServletRequestrequest,HttpServletResponseresponse){IExeclDaoiexecldao=newExeclDao();inta=0;Listlist=newArrayList();Sheetsheet=null;try{request.setCharacterEncoding("gb2312");response.setContentType("text/html");response.setCharacterEncoding("gb2312");Stringfilename=request.getParameter("filename");System.out.println(filename);Filefile=newFile(filename);Workbookworkbook=Workbook.getWorkbook(file);sheet=workbook.getSheet(0);intcol=sheet.getColumns();System.out.println(col);introw=sheet.getRows();System.out.println(row);Stringresult[][]=newString[col][row];Cellcell;for(inti=0;i<col;i++){for(intj=0;j<row;j++){try{cell=sheet.getCell(i,j);result[i][j]=cell.getContents();}catch(Exceptione){e.printStackTrace();}}}Customers_companycustomers_company=null;Customers_company_contactcustomers_company_Contact=null;Customers_company_addresscustomers_company_address=null;for(intn=1;n<row;n++){//循环execl表里的每一行customers_company=newCustomers_company();customers_company_Contact=newCustomers_company_contact();customers_company_address=newCustomers_company_address();if(iexecldao.findcustomers_company(result[0][n])>0){//判断表里面的公司名称是否和数据库里面的重复Stringmess=file.getName()+"表中第"+(n+1)+"行公司名为:"+result[0][n]+"数据库中以存在";list.add(mess);}else{customers_company.setCompany(result[0][n]);customers_company.setCompany_simple(result[1][n]);customers_company.setCompany_phone(result[2][n]);customers_company.setFax(result[3][n]);if(result[4][n].trim().equals("")){//如果没空,且给个默认值为0result[4][n]="0";customers_company.setCustomers_company_id(Integer.parseInt(result[4][n]));}else{customers_company.setCustomers_company_id(Integer.parseInt(result[4][n]));}customers_company.setPark(result[5][n]);customers_company_Contact.setContact_name(result[6][n]);if(result[7][n].trim().equals("")){//如果为空,则给个默认日期Dated=newDate(Date.parse("1/10/1988"));customers_company_Contact.setContact_birthday(d);}else{Dated=newDate(Date.parse(result[7][n]));//将输入的表里的日期格式转型customers_company_Contact.setContact_birthday(d);}customers_company_Contact.setContact_address(result[8][n]);customers_company_Contact.setContact_zip(result[9][n]);customers_company_Contact.setContact_telephone(result[10][n]);customers_company_Contact.setContact_email(result[11][n]);customers_company_Contact.setContact_msn(result[12][n]);customers_company_Contact.setContact_qq(result[13][n]);customers_company_Contact.setContact_department(result[14][n]);customers_company_Contact.setContact_post(result[15][n]);customers_company_Contact.setSign(result[16][n]);customers_company_Contact.setAccount(result[17][n]);customers_company_Contact.setPassword(result[18][n]);customers_company_Contact.setContact_hphone(result[19][n]);customers_company_Contact.setActive(result[20][n]);customers_company_Contact.setSex(result[21][n]);customers_company_Contact.setContact_city(result[22][n]);customers_company_Contact.setContact_area(result[23][n]);customers_company_Contact.setPermission(result[24][n]);customers_company_address.setCity(result[25][n]);customers_company_address.setArea(result[26][n]);customers_company_address.setAddress(result[27][n]);customers_company_address.setZip(result[28][n]);customers_company_address.setSign(result[29][n]);if(result[30][n].trim().equals("")){//如果为空则给个默认值为0result[30][n]="0";customers_company_address.setAddress_type_id(Integer.parseInt(result[30][n]));}else{customers_company_address.setAddress_type_id(Integer.parseInt(result[30][n]));}a=iexecldao.insertExecl(customers_company,customers_company_Contact,customers_company_address);}}PrintWriterout=response.getWriter();JSONArrayjsonArray=JSONArray.fromObject(list);out.println(jsonArray);out.flush();out.close();workbook.close();}catch(Exceptione){e.printStackTrace();}}
解决方案四:
dao层的代码publicintinsertExecl(Customers_companycustomers_company,Customers_company_contactcustomers_company_Contact,Customers_company_addresscustomers_company_address){try{con=ConnectionFactory.getConnection();sql="insertintocustomers_company(company,company_simple,company_phone,fax,customers_id,park)values('"+customers_company.getCompany()+"','"+customers_company.getCompany_simple()+"','"+customers_company.getCompany_phone()+"','"+customers_company.getFax()+"','"+customers_company.getCustomers_company_id()+"','"+customers_company.getPark()+"')";sql1="selectmax(customers_company_id)ascustomers_company_idfromcustomers_company";con.setAutoCommit(false);st=con.prepareStatement(sql);num=st.executeUpdate();st1=con.prepareStatement(sql1);rs=st1.executeQuery();while(rs.next()){sql2="insertintocustomers_company_contact(contact_name,contact_birthday,contact_address,contact_zip,contact_telephone,contact_email,contact_msn,contact_qq,contact_department,contact_post,sign,customers_company_id,account,password,contact_hphone,active,sex,contact_city,contact_area,permission)"+"values('"+customers_company_Contact.getContact_name()+"','"+customers_company_Contact.getContact_birthday()+"','"+customers_company_Contact.getContact_address()+"','"+customers_company_Contact.getContact_zip()+"','"+customers_company_Contact.getContact_telephone()+"','"+customers_company_Contact.getContact_email()+"','"+customers_company_Contact.getContact_msn()+"','"+customers_company_Contact.getContact_qq()+"','"+customers_company_Contact.getContact_department()+"','"+customers_company_Contact.getContact_post()+"','"+customers_company_Contact.getSign()+"','"+rs.getInt("customers_company_id")+"','"+customers_company_Contact.getAccount()+"','"+customers_company_Contact.getPassword()+"','"+customers_company_Contact.getContact_hphone()+"','"+customers_company_Contact.getActive()+"','"+customers_company_Contact.getSex()+"','"+customers_company_Contact.getContact_city()+"','"+customers_company_Contact.getContact_area()+"','"+customers_company_Contact.getPermission()+"')";st2=con.prepareStatement(sql2);num1=st2.executeUpdate();sql3="insertintocustomers_company_address(city,area,address,zip,sign,customers_company_id,address_type_id)values('"+customers_company_address.getCity()+"','"+customers_company_address.getArea()+"','"+customers_company_address.getAddress()+"','"+customers_company_address.getZip()+"','"+customers_company_address.getSign()+"','"+rs.getInt("customers_company_id")+"','"+customers_company_address.getAddress_type_id()+"')";st3=con.prepareStatement(sql3);num2=st3.executeUpdate();}if(num>0&&num1>0&&num2>0){System.out.println(num);System.out.println(num1);System.out.println(num2);flag=true;con.commit();}}catch(SQLExceptione){//TODOAuto-generatedcatchblocktry{con.rollback();}catch(SQLExceptione1){//TODOAuto-generatedcatchblocke1.printStackTrace();}e.printStackTrace();}finally{ConnectionClose.close(rs,st,con);if(st1!=null){try{st1.close();}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}if(st2!=null){try{st2.close();}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}if(st3!=null){try{st3.close();}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}}return0;}

时间: 2024-09-17 04:52:48

进度条的问题的相关文章

C#在状态栏中,自绘进度条,

别的都没什么好说的了,说说这个在状态栏中,画进度条的办法吧.偶是做网站的,一直很羡慕FTP软件中,地址栏中的进度条,那么酷....一直在猜想,人家是怎么把进度条控件..放到地址栏上的??????? - -!! 汗...前几天因为工作需要,用UTF格式来写WEB程序,还要成批处理.写了这软件.一时灵感,试了试居然成功的自绘了进度条. 下面是源码: (另:状态栏name: stat 三个item 分别是: stat_1 stat_2 stat_3 ,stat_3属性设置成自绘.***********

圆形进度条定制

// // HYBCircleProgressBar.h // CircleBarProject // // Created by huangyibiao on 14-8-16. // Copyright (c) 2014年 Uni2Uni. All rights reserved. // #import <UIKit/UIKit.h> #import <QuartzCore/QuartzCore.h> /*! * @brief 圆形进度条 * @author huangyibia

请问word2007样式的进度条的实现原理

问题描述 请问word2007样式的进度条的实现原理 请问word2007样式的进度条的实现原理,将tolbar和trackbar放在状态栏上是怎么实现的呢? 解决方案 http://www.jb51.net/article/71269.htm

js插件YprogressBar实现漂亮的进度条效果

  以下为你介绍js插件YprogressBar实现漂亮的进度条效果:       ProgressBar.js 是一个借助动态 SVG 路径的漂亮的,响应式的进度条效果.使用 ProgressBar.js 可以很容易地创建任意形状的进度条.这个 JavaScript 库提供线条,圆形和方形等几个内置的形状,但你可使用 Illustrator 或任何其它的矢量图形编辑器创建自己的进度条效果. 简介 YprogressBar是一款基于HTML5的进度条插件. YprogressBar是一款轻量级进

带文字的进度条

在下载安装的过程中,我们经常会看到带有文字的进度条,它能给人一种直观的概念.在VC中也有进度条的控件,但它不能显示文字.今有一CProgressCtrl类的派生类CTextProgressCtrl就有完成这样的工作.两种控件运行情况的对比如下: 下面介绍CTextProgressCtrl类的具体使用过程: 1. 运行VC,建立一个名为progressDemo的基于对话框的程序,在对话框中加入两个progressCtrl,然后把TextProgressCtrl.cpp和TextProgressCt

php+ajax文件上传进度条

ajax|上传 代码分为以下部分: demo.php - 上传过程处理 PLAIN TEXTPHP: <?php include 'UploadProgressMeter.class.php'; $fileWidget = new UploadProgressMeter(); if ($fileWidget->uploadComplete()) {        // 上传完毕的时候,从iframe发送一个js到主窗口表示一切ok        echo $fileWidget->fin

CSS3网页制作教程:闪烁跳跃的进度条

文章简介:今天为大家带来另一款更具个性化的进度条:CSS3闪烁跳跃的进度条. 今天为大家带来另一款更具个性化的进度条:CSS3闪烁跳跃的进度条. 这个示例的原理和以前的都是一样的,都是通过大量的css3属性来实现的,如:animation.transform.keyframes等等属性.值得注意的是这个示例采用了结构性伪类选择符E:nth-child(n),来进行对HTML元素的选择以及控制输出.相信这个伪类选择符在将来会是一个很强大的一个工具.推荐大家多多了解以及实践使用. 这个伪类选择符E:

CSS3可按进度变色的进度条

今天是周末,看到一款利用CSS3实现的进度条应用,觉得非常棒,就将它分享给大家,并且将这款CSS3进度条的实现过程大致整理了一下,实现的关键是根据当前的进度需要能改变进度条的背景颜色.下面是效果图: 查看在线演示 从外观上来看,这款进度条还是比较优雅的,有jQuery UI的风格.下面我们来看看具体实现的过程.主要是两部分代码,HTML和CSS3. HTML代码: <input type="radio" class="radio" name="pro

html5实现进度条功能效果

html5实现进度条功能效果非常和谐   <script type="text/javascript"> var i = 0; var res = 0; var context = null; var total_width = 300; var total_height = 34; var initial_x = 20; var initial_y = 20; var radius = total_height/2; window.onload = function()

ASP上传的进度条实时反映上传情况

asp中使用组件上传时,有点麻烦就是不知道上传进度是多少,虽然有的提供了上传进度条,例如abcupload(下载地址:http://www.websupergoo.com)已经提供了显示当前上传状态的方法,里面就有专门的实例(在安装目录的Examples下面的progressupload.htm),它是提交数据的同时弹出一个反映进度的页面(progressbar.asp) 然后通过这个页面自刷新来每隔一点时间获取当时的上传状态,然后把它们显示出来,但是用页面自刷新的方法效率比较低,不不好调节刷新