『壹』 javaWEB MVC 模式下的進度條 實現
按照你當前的業務要求只能有Ajax進行處理,網上有很多進度條方法,給你個例子,你自己研究下。
『貳』 想在網頁做一個上傳進度條,後台用JAVA WEB,需要用線程來做嗎
用個公共類中加個靜態變數,一個不停修改數據,另一個不停查詢數據顯示。前台用個遞歸,到100%終止就行了。
『叄』 jsp中用java實現多文件上傳時如何附帶顯示進度條
這個要多線程實現,我私信發你吧,注意查收一下,滿意就給我過了
『肆』 java web 伺服器端執行的進度條
開始頁面:start.jsp
<%@ page contentType="text/html; charset=GBK" %>
<% session.removeAttribute("task"); %>
<jsp:useBean id="task" scope="session" class="progress.TaskBean"/>
<% task.setRunning(true); %>
<% new Thread(task).start(); %>
<jsp:forward page="status.jsp"/>
狀態頁面:status.jsp
<%@ page contentType="text/html; charset=GBK" %>
<jsp:useBean id="task" scope="session" class="progress.TaskBean"/>
<HTML>
<HEAD>
<TITLE>JSP進度條</TITLE>
<% if (task.isRunning()) { %>
<script type="" LANGUAGE="JavaScript">
setTimeout("location='status.jsp'", 1000);
</script>
<% } %>
</HEAD>
<bODY bgcolor="">
<H1 ALIGN="CENTER">JSP進度條</H1>
<H2 ALIGN="CENTER">
結果: <%= task.getResult() %><BR>
<% int percent = task.getPercent(); %>
<%= percent %>%
</H2>
<TABLE WIDTH="60%" ALIGN="CENTER"
CELLPADDING=0 CELLSPACING=2>
<TR>
<% for (int i = 10; i <= percent; i += 10) { %>
<TD WIDTH="10%" height="10" BGCOLOR="red"> </TD>
<% } %>
<% for (int i = 100; i > percent; i -= 10) { %>
<TD WIDTH="10%"> </TD>
<% } %>
</TR>
</TABLE>
<TABLE WIDTH="100%" BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR>
<TD ALIGN="CENTER">
<% if (task.isRunning()) { %>
正在執行
<% } else { %>
<% if (task.isCompleted()) { %>
完成
<% } else if (!task.isStarted()) { %>
尚未開始
<% } else { %>
已停止
<% } %>
<% } %>
</TD>
</TR>
<TR>
<TD ALIGN="CENTER">
<BR>
<% if (task.isRunning()) { %>
<FORM METHOD="GET" ACTION="stop.jsp">
<INPUT TYPE="SUBMIT" ="停止">
</FORM>
<% } else { %>
<FORM METHOD="GET" ACTION="start.jsp">
<INPUT TYPE="SUBMIT" ="開始">
</FORM>
<% } %>
</TD>
</TR>
</TABLE>
</BODY></HTML>
停止頁面:stop.jsp
<%@ page contentType="text/html; charset=GBK" %>
<jsp:useBean id="task" scope="session" class="progress.TaskBean"/>
<% task.setRunning(false); %>
<jsp:forward page="status.jsp"/>
業務邏輯bean:TaskBean.java
package progress;
import java.io.Serializable;
public class TaskBean
implements Runnable, Serializable {
private int counter;
private int sum;
private boolean started;
private boolean running;
private int sleep;
public TaskBean() {
counter = 0;
sum = 0;
started = false;
running = false;
sleep = 100;
}
protected void work() {
try {
Thread.sleep(sleep);
counter++;
sum += counter;
}
catch (InterruptedException e) {
setRunning(false);
}
}
public synchronized int getPercent() {
return counter;
}
public synchronized boolean isStarted() {
return started;
}
public synchronized boolean isCompleted() {
return counter == 100;
}
public synchronized boolean isRunning() {
return running;
}
public synchronized void setRunning(boolean running) {
this.running = running;
if (running) {
started = true;
}
}
public synchronized Object getResult() {
if (isCompleted()) {
return new Integer(sum);
}
else {
return null;
}
}
public void run() {
try {
setRunning(true);
while (isRunning() && !isCompleted()) {
work();
}
}
finally {
setRunning(false);
}
}
}
『伍』 java多文件上傳顯示進度條
使用 apache fileupload ,spring MVC jquery1.6x , bootstrap 實現一個帶進度條的多文件上傳,由於fileupload 的局限,暫不能實現每個上傳文件都顯示進度條,只能實現一個總的進度條,效果如圖:
packagecom.controller;
importjava.util.List;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
importjavax.servlet.http.HttpSession;
importorg.apache.commons.fileupload.FileItemFactory;
importorg.apache.commons.fileupload.ProgressListener;
importorg.apache.commons.fileupload.disk.DiskFileItemFactory;
importorg.apache.commons.fileupload.servlet.ServletFileUpload;
importorg.apache.log4j.Logger;
importorg.springframework.stereotype.Controller;
importorg.springframework.web.bind.annotation.RequestMapping;
importorg.springframework.web.bind.annotation.RequestMethod;
importorg.springframework.web.bind.annotation.ResponseBody;
importorg.springframework.web.servlet.ModelAndView;
@Controller
{
Loggerlog=Logger.getLogger(FileUploadController.class);
/**
*upload上傳文件
*@paramrequest
*@paramresponse
*@return
*@throwsException
*/
@RequestMapping(value="/upload.html",method=RequestMethod.POST)
publicModelAndViewupload(HttpServletRequestrequest,
HttpServletResponseresponse)throwsException{
finalHttpSessionhs=request.getSession();
ModelAndViewmv=newModelAndView();
booleanisMultipart=ServletFileUpload.isMultipartContent(request);
if(!isMultipart){
returnmv;
}
//Createafactoryfordisk-basedfileitems
FileItemFactoryfactory=newDiskFileItemFactory();
//Createanewfileuploadhandler
ServletFileUploapload=newServletFileUpload(factory);
upload.setProgressListener(newProgressListener(){
publicvoipdate(longpBytesRead,longpContentLength,intpItems){
ProcessInfopri=newProcessInfo();
pri.itemNum=pItems;
pri.readSize=pBytesRead;
pri.totalSize=pContentLength;
pri.show=pBytesRead+"/"+pContentLength+"byte";
pri.rate=Math.round(newFloat(pBytesRead)/newFloat(pContentLength)*100);
hs.setAttribute("proInfo",pri);
}
});
Listitems=upload.parseRequest(request);
//Parsetherequest
//Processtheuploadeditems
//Iteratoriter=items.iterator();
//while(iter.hasNext()){
//FileItemitem=(FileItem)iter.next();
//if(item.isFormField()){
//Stringname=item.getFieldName();
//Stringvalue=item.getString();
//System.out.println("thisiscommonfeild!"+name+"="+value);
//}else{
//System.out.println("thisisfilefeild!");
//StringfieldName=item.getFieldName();
//StringfileName=item.getName();
//StringcontentType=item.getContentType();
//booleanisInMemory=item.isInMemory();
//longsizeInBytes=item.getSize();
//FileuploadedFile=newFile("c://"+fileName);
//item.write(uploadedFile);
//}
//}
returnmv;
}
/**
*process獲取進度
*@paramrequest
*@paramresponse
*@return
*@throwsException
*/
@RequestMapping(value="/process.json",method=RequestMethod.GET)
@ResponseBody
publicObjectprocess(HttpServletRequestrequest,
HttpServletResponseresponse)throwsException{
return(ProcessInfo)request.getSession().getAttribute("proInfo");
}
classProcessInfo{
publiclongtotalSize=1;
publiclongreadSize=0;
publicStringshow="";
publicintitemNum=0;
publicintrate=0;
}
}
『陸』 java struts2 如何實現下載,並顯示下載進度條
建議放棄吧
『柒』 javaweb的頁面進度條
兩部分:
POI解析Excel文件是否提供介面可以取得完成的進度(百分數),沒有的話也可以弄個假的,處理中每N秒+1%,結束時直接設置為100%,N根據實際處理速度調整,免得最後超過100%...
頁面有很多進度條實現,網路一下就有,需要傳入進度數作為參數,來展現,自己網路一下:jsProgressBarHandler (Dynamic Javascript Progress。第一個就是。
『捌』 javaweb 多文件上傳
有成熟框架 我用過的plupload不錯,滿足你所有要求,帶進度條的。
『玖』 java導入進度條
很簡單,因為數據讀到集合所用的時間遠遠不如資料庫的存儲,因此只要計算插入資料庫的進度即可。做法是:在讀入資料庫的時候 根據集合的大小生成一個最大進度為集合長度的進度條,每成功寫入資料庫一條,進度條 +1。
『拾』 js進度條與後台更新實現進度條遮罩效果
<script>js進度條與後台更新實現進度條遮罩效果</script>