当前位置:编程学习 > JS >>

jsp 导出文件实例代码

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

补充:Web开发 , Jsp ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,