I have a requirement where I need to download multiple files from unix server to user local machine (windows) on some user action in JSP. To achieve this task, I am writting an applet embedded in JSP which is making an HTTP connection to servlet running on the server via post method.My code is working fine if I run from RAD but when I run through JSP documents are not getting downloaded but however call to servlet is happening. To test whether my servlet is returing back to applet i am sending a string to applet from servlet via outputstream object and printing it using paint method and I am able to print the value on the applet.
I am kind of stuck here on how to resolve the issue of downloading the documents to local machine. Any help will be highly appreciated
The servlet is getting called from applet on urlConnection.getInputStream() line. The servlet scans the files in folder under C:\\EPOSTemp and I am able to see the filenames in console. EVen servlet is writing the String by name "Madhu" to outPutStream via outputToApplet.writeUTF("Madhu") which I am able to fetch the value from applet and display it on the browser where applet is running.
Regarding my query on making applet as signed, I meant do I need to make applet as signed if I have to download the files to local machine after receiving the object stream from servlet. Please help..?
You don't need an applet at all. In fact, applets are discouraged at this stage. When the user clicks on a link to get the files, zip up the files and return the zip file as the response. Be sure to set the response headers appropriately.
Thanks Bear Bibeault for the reply. This is what I was doing initially. When user clicks on the link, my code was downloading all the documents zipped together to user machine by prompting a save dialogue to the user to save the zip file. But unfortunately users don't want to have the save prompt message and they want individual documents to be downloaded. Because of this I am using the applet approach. Kindly help with your ideas. Many thanks.....
How many documents are we talking about? If it's just a few, then the web page can just show links for all of them. I agree with Bear that applets are almost never the answer these days. Plus (to paraphrase the Rolling Stones), users don't always get what they want, they sometimes get what they need instead. And the way to download several files with one click is a zip file.
On an average we will be having 5 documents for each request. After downloading these documents, my code need to open the Lotus notes and attach the downloaded files so that user can send email to intended recpient. In my case users are very lazy to click the save button (Hence this post) to save the zip file to local machine and I am sure they will not agree on having the link for each document because they will have to click so many times to download the documents to local machine. I will be very gald of you guys if I get an feasible approach using applet to achieve this. Many thanks in advance.....
Well, if you're determined to go ahead with the applet, I would start by simplifying the code. Downloading a file should be easy, just read the bytes from the file on the server and write them to the response. And on the client just read the bytes from the response and write them to a file until there aren't any more. Anything else (like that object serialization business you have there) is unnecessary for a simple file transfer.
Thanks Paul. Do I need to make the applet as signed If i have to download the files from server to local machine. I tried from local RAD websphere by calling the servlet via applet and I was able to transfer the contents locally from one folder to another folder.Below is the flow
JSP page intiaites applet which calls servlet and servlet will get contents from local folder (for eg:A) and passes it thru outputstream to applet and applet will read the contents and file it to an other folder in the same machine (for eg: B). This was achieved after making applet as selfsigned using keytool and jarsigner commands.
However after deploying the project on the destination server, I am unable to achieve the same but I have confirmed that applet to servlet and viceversa communication is happening. Do I need to sign the applet again to download files locally?
I need to make multiple calls to a servlet from single instance of Applet.. i.e., flow is like this
1) Applet calls servlet requesting for some info (filenames)
2) Servlet sends the requested info (filenames)
3) Applet iterates based on the info (number of filenames) provided and calls servlet to send contents of each filename to applet. In a loop applet downloads file one by one making multiple calls to servlet requesting for content..
Once the documents are downloaded how to stop/terminate the applet. After downloading if user goes to the webpage, the applet again begins to download the documents. I want to stop/terminate the applet after its first execution no matter even if user keeps the browser as is?. Please help.........