Java 使用Struts在JSP中显示BLOB MySQL中的文档文件

Java 使用Struts在JSP中显示BLOB MySQL中的文档文件,java,mysql,jsp,struts,blob,Java,Mysql,Jsp,Struts,Blob,我需要从MySQL数据库中检索一个.doc文件,该文件存储为BLOB数据类型。这是我的动作文件代码 List<CandyDetails> det = new ArrayList<CandyDetails>(); CandyDetails details = new CandyDetails(); ResultSet rs3 = st.executeQuery("SELECT * FROM seek_resume WHERE seek_code = '"+seekCode

我需要从MySQL数据库中检索一个.doc文件,该文件存储为BLOB数据类型。这是我的动作文件代码

List<CandyDetails> det = new ArrayList<CandyDetails>();
CandyDetails details = new CandyDetails();

ResultSet rs3 = st.executeQuery("SELECT * FROM seek_resume WHERE seek_code = '"+seekCode+"'");
   while(rs3.next()){
      details.setResume(rs3.getBytes(2));
}

request.setAttribute("candyDet", det);
return mapping.findForward("success");
这是我的JSP页面代码

<logic:iterate name="candyDet" id="in">
     ${in.resume}
</logic:iterate>
每次刷新时,B@后面的数字似乎都在变化


我正在使用Struts 1.3。

将其放在Action类中

String qry="SELECT * FROM seek_resume WHERE seek_code = '"+seekCode+"'"";
Statement st = con.createStatement(qry);                
ResultSet rs = st.executeQuery();
if(rs.next()) //show one document
{
    byte[] bytearray = new byte[1048576];
    int size=0;
    InputStream is = rs.getBinaryStream(2);
   // String contentType=rs.getString("content_type");
    String contentType = "application/msword"; //doc
    String contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; //docx                     
    response.reset();
    response.setContentType(contentType);
    while((size=is.read(bytearray))!= -1 )
    {
        response.getOutputStream().write(bytearray,0,size);
    }
}

//return null;
-----jsp----

<a href="showDoc.do?seekCode=${seekCode}" target="_blank"> View</a>
//根据需要放置链接

通过将代码传递给action类来调用action类,action类将以doc作为响应

您可以使用ApachePOI将文档显示为内联内容

String qry="SELECT * FROM seek_resume WHERE seek_code = '"+seekCode+"'"";
Statement st = con.createStatement(qry);                
ResultSet rs = st.executeQuery();
if(rs.next()) //show one document
{
    byte[] bytearray = new byte[1048576];
    int size=0;
    InputStream is = rs.getBinaryStream(2);
   // String contentType=rs.getString("content_type");
    String contentType = "application/msword"; //doc
    String contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; //docx                     
    response.reset();
    response.setContentType(contentType);
    while((size=is.read(bytearray))!= -1 )
    {
        response.getOutputStream().write(bytearray,0,size);
    }
}

//return null;
<a href="showDoc.do?seekCode=${seekCode}" target="_blank"> View</a>