How to retrieve a file from servlet (through an Applet)?
Hello all,
I have a servlet that responds with an Excel file when called within the browser, e.g.http://localhost:8080/db_connect/iisgetxls
The servlet looks as follows:
publicclass GetXLSFromDBextends HttpServlet{
publicvoid doGet(HttpServletRequest req, HttpServletResponse response)
throws ServletException, IOException{
OutputStream out =null;
try{
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition","attachment; filename=sampleName.xls");
WritableWorkbook w = Workbook.createWorkbook(response.getOutputStream());
WritableSheet s = w.createSheet("Demo", 0);
s.addCell(new Label(0, 0,"Hello World"));
w.write();
w.close();
System.out.println("XLS written!");
}
catch (Exception e){
thrownew ServletException("Exception in Excel Sample Servlet", e);
}
finally{
if (out !=null)
out.close();
}
}
}
This works like charm. Now I would like to invoke the same behaviour from an Applet. I.e. I created a JButton "Get XLS" and this button should now trigger the reception of the file like in the browser, popping up a "save as" dialog (after sending some information to the servlet as well, but I know how to handle this). How should the code look like to achieve this behaviour? What is -technically spoken- the mechnism that the browser uses to get the file in reponse? The servlet connection from an Applet has so many methods that I cannot figure the correct "composition".
Thanks in advance
Jan

