apache - Check if stream from HttpServletResponse was download by client - JAVA -
basically, system generates url's download files server. make using struts result of type 'stream'. work great. want notice each file downloaded, if downloaded.
i've been searching while don't know how continue. i'm beginner this.
**
new action:
**
public string download(){ try { string path = init.getwebinfpath() + uploadmanager.getinstance().getproperty("upload_dir") + content.getzipfile(); file = new fileinputstream(new file(path)); } catch (exception e) { return error; } long overallsize = null; try { overallsize = file.getchannel().size(); } catch (ioexception e) { e.printstacktrace(); } response.setcontenttype("application/zip"); response.addheader("content-disposition", "attachment; filename=\""+content.getzipfile()+"\""); response.setheader("content-length", string.valueof(overallsize)); servletoutputstream sos = null; try { sos = response.getoutputstream(); int read; read = file.read(); while (read>0){ sos.write(read); read = file.read(); } } catch(exception e){ return error; } return none; }
**
new xml:
**
<struts> <package name="content" namespace="/content" extends="default"> <action name="download" class="com.tictapps.adserver.web.content.contentaction" method="download"> <result name="none"/> </action> </package> </struts>
once return stream result, you've no more control on outputstream.
the first ways coming mind ensure file downloaded are:
write directly outputstream, , return result
none(that mapped nothing) instead ofsuccess(that you've mapped stream). have full control on response, lose of framework automatisms. works, i've did in past.create custom result based on stream result's source code, eg.
streamwithconfirm, , add logic need in it.you in custom interceptor (in post-invocation part, obviously), i'm not sure , btw hardest of 3 newbie.
the n. 1 (adapting code linked answer) should need.
Comments
Post a Comment