I have a Java Applet application. The use case is as follows:
The users invoke a URL which is mapped to a Servlet. The servlet as a response returns a JSP page from which the users can navigate in the UI. The entire UI is made of Swing [basically a JApplet]. The events in the UI are handled in the traditional manner [ActionListeners, SelectionListeners…]. Now I have the following requirement:
There is a file in the server directory that I am supposed to allow the users to download through my application. I need to give the users a link in my UI, the clicking of which will trigger the download.
Can this be done considering the security features of JApplets? Also consider the event handling mechanism of Swing components.
The options for a sand-boxed applet.
There are 2(.2) ways to go (that I can immediately think of).
AppletContextequivalent for the fact that it returns abooleanto indicate success/failure. The applet based version might fail, and if it does, it does so silently. See also the demo. of the BasicService.A trusted applet can use this process.
JFileChooserto allow the user to decide where to save theFile.File(indicating the action was not cancelled) proceed with saving.InputStreamfrom theURL.OutputStreamto theFile.InputStream, write them to theOutputStream.