I follow the online approach , why not successful :
I write a class MyMultiPartRequest, achieve MultiPartRequest interface, and all the JakartaMultiPartRequest copied code , and then modify parseRequest methods. After the change as follows:
private List<FileItem> parseRequest(HttpServletRequest servletRequest, String saveDir) throws FileUploadException {
DiskFileItemFactory fac = createDiskFileItemFactory(saveDir);
ServletFileUpload upload = new ServletFileUpload(fac);
//添加监听器
upload.setProgressListener(new ProgressListener() {
@Override
public void update(long pBytesRead, long pContentLength, int pItems) {
int percent = (int) (((float)pBytesRead / (float)pContentLength) * 100);
ActionContext.getContext().getSession().put("process", percent + "%");//将进度百分比放到session中。
System.out.println("--------"+percent);//输出一下上传的进度
}
});
upload.setSizeMax(maxSize);
return upload.parseRequest(createRequestContext(servletRequest));
}
then configure the parser is in struts.xml in : MyMultiPartRequest. As follows :
<!--ProgressListener -->
<bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest" name="requestParser"
class="com.gycenter.listener.MyMultiPartRequest" scope="default"/>
<constant name="struts.multipart.handler" value="requestParser" />
<!-- ProgressListener end -->
class = "com.gycenter.listener.MyMultiPartRequest" is a package path above me where the parser class
That's it . Then the front desk I was using every second ajax call a method, which is the percentage of the session that get uploaded to the method as follows:
public void uploadProgress(){
try {
String process = (String) ActionContext.getContext().getSession().get("process");
System.out.println("文件已经上传"+process);
getResponse().getWriter().print(process);
} catch (IOException e) {
e.printStackTrace();
}
}
After doing so , I upload a file every second call about this method, but here come the process output is null
parser and custom : MyMultiPartRequest classes phrase no output.
Seek expert answers.
Oh file upload method is the same as file upload and struts2
------ Solution ------------------------------------ --------
problem lies in the foreground , right
------ Solution ------------------------ --------------------
you see is not the effect
------ Solution ----------------------------- ---------------
these good results , go back to try.
------ Solution ---------------------------------------- ----
same requirements. . . . .
------ For reference only -------------------------------------- -
ah , I have no one to put you on top .....
------ For reference only ------------------ ---------------------
great God is how you do it! Seeking ideas seeking code ! ! ! Oh Great God of heaven too !
------ For reference only -------------------------------------- -
I'm not a big God , a passerby playing soy sauce
If you are interested, you can go to download a copy of my recent resource
This is achieved using js upload without refresh , there is no ssh, on a servlet
I want to declare it: This upload is not compatible with the IE browser , IE always reported because no permission error ,
I guess IE should be set free upload , non- flash can not be used ,
my jquery js code and there is no relationship , because I despise ( and exclusion ) jquery, if you are too dependent on jquery, jquery or leave it live, then forget it !
------ For reference only -------------------------------------- -
where to download ? To address ah huh
------ For reference only --------------------------------- ------
do understand there is no one ah ! ! Examples of online nor can not run , why do online say this is it! ! ! !
------ For reference only ---------------------------------- -----
http://download.csdn.net/detail/s478853630/5992259
------ For reference only --------------- ------------------------
very powerful , if a little thin longer the better
没有评论:
发表评论