不刷新页面提交表单,并显示进度条

 

====index.jsp========

<%@ page  pageEncoding="GBK" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title></title>
<script>
  var thread;
  var isfirst = true;
  function upload(){
      try{
          document.forms[0].submit();
      }catch(exception){
         alert(exception.name);
      }
      p.style.display = '';
      thread = window.setInterval("startmove()",100);
   var my = document.getElementByIdx("up"); 
   isfirst = false; 
  }
  var w = 1;
  var flag = 'right';
 
  function startmove(){
       if(flag == 'right'){
       w += 2;
       if(w>95){
      w = 95;
         flag = 'left';   
       }
    }else{
      w -= 1;
   if(w<1){
     flag = 'right';  
     id1.width = '';
     return;
   }
    
       id1.width = w + '%';
  }
 
  function stopmove(){
      window.clearInterval(thread);  
   p.style.display = "none";    
   if(!isfirst){
     getResult();
   }
   w = 1;
  
  }
 
 
  var req;
  var url = 'http://localhost:8080/webtest/msg.jsp';
  function getResult() {
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    } else if (window.ActiveXObject) {       
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    req.open("GET", url, false);
    req.send(null);
    alert( req.responseText);
  }

</script>
</head>

<body>
<div id="p" style="display:none">
<table width="572" height="30" border="0" cellspacing="0" cellpadding="0">
  <tr align="left">
    <td id="id1" width="0" bgcolor="#999999"/>
    <td id="id2" width="5%" bgcolor="#0033FF"/>
    <td id="id3" width="95%" bgcolor="#999999"/>
  </tr>
</table>
</div>
<br>
  <form action = "something.jsp" enctype="multipart/form-data" method="post" target="up">
    <input name="file" type="file" >
    <input  type="button" onClick="upload()" value="提交" /> 
  </form>
 
<% System.out.println("aaaa"); %>
<p><br>
  <span id="msg"></span>
</p>
<iframe style="display:none" οnlοad="stopmove()" name="up"></iframe>
</body>
</html>

 

====== something.jsp======

<%@ page contentType="text/html; charset=GBK" %>
<%
    response.setHeader("Cache-Control", "no-cache");
  
   
   
    Thread.sleep(5000);//do something
    System.out.println(">>>>");
    session.setAttribute("msg","上传成功!");
%>

 

===== msg.jsp=====

<%@ page contentType="text/html; charset=GBK" %>
<%
String msg = (String)session.getAttribute("msg");

System.out.println("msg:"+msg);
if(msg == null)
  out.write("");
else{
 out.write(msg);   
}
%>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值