publicclass TestOpenExcel extends HttpServlet {
privatestaticfinal String url = "D:/test.xls";
protectedvoid doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition", "inline;filename="" + "test.xls"+ "";");
ServletOutputStream sos = response.getOutputStream();
FileInputStream fis = new FileInputStream(url);
BufferedOutputStream bos = new BufferedOutputStream(sos);
byte[] bytes = newbyte[8192];
bos.write(bytes, 0, fis.read(bytes));
fis.close();
sos.close();
bos.close();
}
protectedvoid doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}