javascript写的进度条结合struts的action线程判断

来源:互联网 发布:微博域名搜索 编辑:程序博客网 时间:2024/06/07 17:18

 <1>action:IsGoAction

package com.dreamers.search;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class IsGoAction extends ActionSupport{

 /**
  *
  */
 private static final long serialVersionUID = 1L;
 
 public String execute(){
  String name =(String)ActionContext.getContext().getSession().get("nn");
 
  ThreadGroup group = Thread.currentThread().getThreadGroup();
  ThreadGroup parent = null;
  while ( (parent = group.getParent()) != null ) {
   group = parent;
   }
  Thread[] threads = new Thread[group.activeCount()];
  group.enumerate(threads);
  for(int i = 0; i < threads.length; i++){
   if(threads[i].getName().equals(name)){
    while(threads[i].isAlive()){
    
     
    }
   }
 }
  System.out.println("isgo action");
  try {
   Thread.sleep(1000);
  } catch (InterruptedException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return SUCCESS;
 
}
}

<2>wait.jsp

<%@ page language="java" import="java.util.*" import ="java.io.File"
 pageEncoding="GBK"%>
<%@ page contentType="text/html;charset=GBK"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
  

        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Javascript Progress Bar Demo - jb51.net</title>
        <script type="text/javascript" src="http://www.jb51.net/jslib/jquery/jquery.js"></script>
        <style type="text/css">
            #progress {background: white; height: 20px; padding: 2px; border: 1px solid green; margin: 2px;}
            #progress span {background: green; height: 16px; text-align: center; padding: 1px; margin: 1px;
                display: block; color: yellow; font-weight: bold; font-size: 14px; width: 0%;}
        </style>

        <script type="text/javascript">

            var progress_node_id = "progress";
            function SetProgress(progress) {
                if (progress) {
                    $("#" + progress_node_id + " > span").css("width", String(progress) + "%");
                    $("#" + progress_node_id + " > span").html(String(progress) + "%");
                }
            }

            var i = 0;
            function doProgress() {
               
                if (i <= 100) {
                    setTimeout("doProgress()",150);
                    SetProgress(i);
                    i++;
                }
                if(i>100){
               document.form.submit();
                }
            }

            $(document).ready(function() {
                doProgress();
            });
       
        </script>
  
  </head>
 
 
<body>

<form action="isgo.action" id = "form" name="form">
</form>
<div id="progress"><span> </span></div>     //通过设置span的样式来实现进度条,注意进度条完成的总时间是死值,具体是否完成要看action

</body>

</html>

<3>struts.xml中

<action name="isgo" class="com.dreamers.search.IsGoAction">
 <result name = "success">/previewdoc.jsp</result> //转到下一个jsp

 

原创粉丝点击