当前位置: 移动技术网 > IT编程>开发语言>Jsp > jsp 导出文件实例代码

jsp 导出文件实例代码

2018年04月19日  | 移动技术网IT编程  | 我要评论

public ActionForward exportFile(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        String natLog = "test";
                
        try {
            StringBuilder fileName = null;
            OutputStream output = null;
            
            byte[] streamBytes = natLog.getBytes();
            if (streamBytes == null) {

            } else {
                fileName = new StringBuilder(64);
                fileName.append("export.txt");
                try {
                    output = response.getOutputStream();
                    
                    FileStream.initResponseAsFile(response, fileName.toString(), "MIME/octet-strea");
                    output.write(streamBytes);
                    output.flush();
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    if (output != null) {
                        output.close();
             &n

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网