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 [ActionListener
s, SelectionListener
s...]. 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.
There are 2(.2) ways to go (that I can immediately think of).
AppletContext
equivalent for the fact that it returns a boolean
to indicate success/failure. The applet based version might fail, and if it does, it does so silently. See also the demo. of the BasicService.JFileChooser
to allow the user to decide where to save the File
.File
(indicating the action was not cancelled) proceed with saving.InputStream
from the URL
.OutputStream
to the File
.InputStream
, write them to the OutputStream
.