8
回答
从数据库中取出word文档的二进制数据怎样显示在jsp页面?
华为云实践训练营,热门技术免费实践!>>>   
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="com.horizon.db.Access"%>
<%
    String path=request.getContextPath();
    System.out.println(path);
    String workid=request.getParameter("workid");   
    String sql = "select * from document_file where recordid='"+workid+"'";
    System.out.println("sql====="+sql);
 
    List listaid = Access.getMultiList(sql, null);
    System.out.println(listaid.size());
    if(listaid.size()>0){
        String fileid = String.valueOf(((List) listaid.get(0)).get(0));
        System.out.println(fileid);
        byte[] byteblob = Access.getBlobContentBytes("DOCUMENT_FILE","FILEBODY","where recordid  ='"+workid+"'","system");       
         
        response.reset();
        response.setHeader("Content-Disposition", "attachement;filename=fujian.doc;");
        //String s=new String(byteblob.getBytes("IS0-8859-1","GBK"));
//        response.setContentType("application/msword;charset=GBK");   
        response.setContentType("application/x-msdownload");
        //response.setContentType("text/html;charset=utf-8");
        OutputStream output=response.getOutputStream(); 
        output.flush(); 
         if(byteblob!=null){
                InputStream  in = new ByteArrayInputStream(byteblob); 
                byte[] buf=new byte[4096];
                int len = 0;                
                while ((len = in.read(buf)) > 0) {
                    output.write(buf, 0, len);                 
                }   
                in.close();
                output.flush();
                output.close();
                output=null;  
                response.flushBuffer();  
                out.clear();  
                out = pageContext.pushBody(); 
             }
    }else{
    %>
    <div>&nbsp;</div>
    <div align="center" style="color:red">相关的正文不存在!</div>

<% }%>

怎么讲获取的word数据显示在jsp页面上,不需要下载


举报
顶部