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

[2595 byte] By [Itsman72a] at [2007-11-26 12:44:23]
# 1
Make your own HTTP request from the applet and send it to servlet.
reflex2javaa at 2007-7-7 16:21:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
try creating hyper links on servlet
reflex2javaa at 2007-7-7 16:21:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Check out the Apache Commons HttpClient package which allows for sending and recieving Http messages. There are samples and a tutorial.

Be aware that the Applet can only make a connection back to the server address that it was loaded from. It has to be exact which means that 127.0.0.1 is not the same as localhost.

tolmanka at 2007-7-7 16:21:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
> Be aware that the Applet can only make a connection> back to the server address that it was loaded from.> It has to be exact which means that 127.0.0.1 is not> the same as localhost.Or sign your applet
LRMKa at 2007-7-7 16:21:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...