How can you tell if the user hit cancel during a download from a Java servlet? What seem to happen for me with IE, the output stream println() blocks. The used hit cancel, but is there a way to time this out or anything like that?
How can you tell if the user hit cancel during a download from a Java servlet?
3.2k views Asked by GC_ At
2
There are 2 answers
1
erickson
On
You won't be able to tell for sure. It depends on how your servlet container is implemented.
When the user hits "Cancel", the browser should close the socket. This will be detectable by the server, of course, but whether the server has the ServletOutputStream "plumbed" directly to the socket's OutputStream is implementation-dependent. If it does, an IOException will be raised the next time the servlet attempts to write data.
If the container buffers output, the servlet might just finish writing data and never know anything went amiss.
Related Questions in JAVA
- Add image to JCheckBoxMenuItem
- How to access invisible Unordered List element with Selenium WebDriver using Java
- Inheritance in Java, apparent type vs actual type
- Java catch the ball Game
- Access objects variable & method by name
- GridBagLayout is displaying JTextField and JTextArea as short, vertical lines
- Perform a task each interval
- Compound classes stored in an array are not accessible in selenium java
- How to avoid concurrent access to a resource?
- Why does processing goes slower on implementing try catch block in java?
- Redirect inside java interceptor
- Push toolbar content below statusbar
- Animation in Java on top of JPanel
- JPA - How to query with a LIKE operator in combination with an AttributeConverter
- Java Assign a Value to an array cell
Related Questions in SERVLETS
- Redirect inside java interceptor
- Which Should i use for date,time,email in servlet?
- Importing a downloaded JAR file into a Servlet
- Execute RequestDispatcher after 5 seconds
- What's the difference between a ServletHandler and a ServletContextHandler in Jetty?
- How to call servlet file from html
- Requested Resource is not available error
- Struts exclude pattern with spring
- How can I get a custom header from the client in Tomcat?
- How to print Jasper reports from servlets?
- The type javax.servlet.ServletContext and javax.servlet.ServletException cannot be resolved
- ServletContext Attribute : Thread Safety test not working
- Servlet ClassNotFoundException when present in a package ... Why?
- How to create a PDF with iText+XMLWorker from servlet using custom font?
- Starting a ScheduledExecutorService from a servlet with a set of parameters
Related Questions in DOWNLOAD
- FIle download via cmd in windows using HTML
- Asp.net /JQuery to show/hide animated gif before download
- How to provide a file download from a JSF backing bean using af:commandMenuItem?
- detecting a file downloaded in selenium java
- java download speed very slow with this code
- How to name downloaded file?
- Download file with Casperjs
- how to pause and resume a download in javafx
- how to download a video from url in xamarin forms
- How to verify the integrity of a linux tarball?
- Save File in javascript clientside using utf-8 string
- file download with curl and php
- How can I Upload a document file in Wordpress and track its download?
- It is possible to download file on p:poll
- Access to the path is denied - different from user
Related Questions in REQUEST-CANCELLING
- Meteor - Requests randomly failing
- Are HTTP requests always cancelled by all browsers if originator iframe is destroyed before it completes?
- What is the Correct HTTP Status Code for a Cancelled Request
- AddScoped dependency with a CancellationToke
- Aborting previous requests of mutation function from useMutation of Apollo client in React causes request to never run
- TCP connections with overlapped I/O
- axios cancellation caught inside of then() instead of catch()
- background worker class cancellation, sets cancellation pending flag but doesn't quit
- How to cancel request in Http Interceptor in angular5?
- AFNetworking cancel post request
- How to detect if HttpClient.CancelPendingRequests was used to cancel pending requests?
- Handling cancelled request with Express/Node.js and Angular
- Axios cancel token cancelling every request
- jQuery - Cancel form submit (using "return false"?)?
- How can you tell if the user hit cancel during a download from a Java servlet?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Wrap
OutputStream#write(),#flush()and#close()in atry-catchblock onIOException. If caught, then it usually means that the enduser has aborted the request.To get a step further, you could also catch on a more servletcontainer-specific exception like
ClientAbortExceptionon Tomcat and clones (which is a subclass ofIOException), but this will make your webapp code unportable to other servletcontainers.Update: to come back on the blocking issue, you'd like to call
flush()after writing a single block of data. This will actually send the data to the client and causeIOExceptionwhen the underlying socket is closed.