闲来无事做的一个小例子:
java 代码
- public class TestOpenExcel extends HttpServlet {
-
- private static final String url = "D:/test.xls";
-
- protected void 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 = new byte[8192];
- bos.write(bytes, 0, fis.read(bytes));
- fis.close();
- sos.close();
- bos.close();
-
-
- }
-
-
- protected void doPost(HttpServletRequest request,
- HttpServletResponse response) throws ServletException, IOException {
- doGet(request, response);
- }
-
- }
|
[@more@]
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/800861/viewspace-922103/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/800861/viewspace-922103/