java进度_(java)实现进度条开发过程⾸先说流程:
1.访问启动任务servlet
达达在线高清2.启动任务servlet开启任务,并跳转掉进度条展⽰页⾯
3.页⾯就绪就调⽤(进度参数获取servlet),此后进度条展⽰页⾯定时调⽤,直到传递过来为100%.
4.获取参数servlet从session中取出任务,并获取任务中的进度参数.返回进度参数给进度展⽰页⾯.
⼀下是各个⽂件代码,⼯程为web⼯程。
1.进度条schedule.css⽂件:
body {
margin:0;
padding:0;
font-family:"宋体";
font-size:12px;
line-height:1.8em;
color:#392b60;
height:100%;
}
/*最外层的div样式*/
.progressOutside {
border:red 1px dotted; /*边框1像素的红⾊虚线*/
width:350px; /*宽度是350像素*/
position:relative; /*相对body位置*/
margin-left:-175px; /*整个div宽度是350,-175px就是向右移动了175像素.正好居中.*/
left:50%; /*左边框距浏览器左边框是屏幕的⼀半.*/
margin-top:150px; /*上边框相对于body顶部35%*/
}
/*标题div样式*/
.progressTitle {
border:greenyellow 1px solid;
line-height:30px; /*设置⾏⾼
padding:0 15px 0; /*内填充 上:0, 右:15像素, 下:0*/
}
/*内容div样式*/
.progressContent {
select返回值border:purple 1px double;
padding:15px;
height:40px !important;
}
/*进度条框*/
.progress {
background:#f0f4f9 url(../imgs/2.gif) repeat-x top; border:yellow 2px solid;
height:15px;
margin:10px 0 0 0 !important; margin:35px 0 0 0; }
/*进度条实体*/
.progressSchedule {
border:red 1px double;
background:url(../imgs/1.gif) repeat-x left top; width:3%;
height:15px;
}
/*进度提⽰框*/
.progressPercent {
text-align:center;
border:green 1px solid;
height:15px;
position:absolute;
display:block;
left:125px;
margin-top:-17px;
width:100px;
}
/*百分⽐提⽰框*/
.textProgress {
border:orange 1px solid;
language中文font-weight:bold;
font-family:tohama;
2.页⾯⽂件invoke.jsp ⽤到了jquery.
css/schedule.css" rel="stylesheet" type="text/css">
java下载过程
Insert title here
进度条标题在此
完成
3.⽤到的ajax get.js⽂件
$(document).ready(function(){
getPercent();
});
function getPercent(){
$.post("process",{userName:'ab'},function(data){
styleId.style.width=data;
$("#bfb").text(data);
if(data!='100%'){
window.setTimeout(getPercent,100);
}else{
if(confirm("Finished?")){
window.location.href="/servlet1/index.html";
}
}
});
4层汉诺塔怎么玩}
4.启动线程servlet Index.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletE
xception, IOException { Progress p = (Progress) Session().getAttribute("progress");
if(p!=null){
System.out.println("Thread Running!");
throw new RuntimeException("线程被占⽤!");
}else{
Progress progress = new Progress();
progress.start();
}
response.ContextPath()+"/invoke.jsp");
5.线程任务类-->要做的任务写在这个⾥⾯Progress.java
public class Progress extends Thread{
Logger logger = Logger(Process.class);
//Getter⽅法省略
private String percent = "";
//Getter⽅法省略
private boolean over = false;
public void run(){
for(int i=1;i<=100;i++){
try {
Thread.sleep(1*100);download是什么意思中文
} catch (InterruptedException e) {
e.printStackTrace();
}
percent = i+"%";
}
if(logger.isDebugEnabled()){
logger.debug("thread run over!");
}
over = true;
}
}
6.取参数servlet-->此servlet是要被页⾯定时的调⽤,Process.java
被调⽤时,会取出当前任务线程,获取当前任务线程中的进度参数,同时将进度参数传到页⾯.
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Progress p = (Progress) Session().getAttribute("progress");
if (p!=null) {
String percent = p.getPercent();
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
}
if(p.isOver()){
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论