struts 中jsp 页面从数据库中取得图片的问题

handle19811106 2005-03-15 02:40:58
我用了struts标签库
<html:img height="98%" alt="BookCover" src="photoAction.do" paramId="bookName" paramName="bookForm" paramProperty="bookName" width="98%" border="0" align="center" />


但是却取不到图片到页面

我的photoAction是:
package book;


import oracle.sql.*;
import book.*;
import org.apache.cocoon.components.language.markup.xsp.EsqlQuery;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import javax.servlet.jsp.jstl.sql.Result;
import oracle.jdbc.driver.*;
import java.sql.*;
import java.io.*;
import oracle.jdbc.driver.*;
import org.apache.struts.action.ActionForm;
import javax.servlet.ServletRequest;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;






/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/

public class photoAction extends Action {

private static final String connTENT_TYPE = "image/gif";
private Result rs;
// private Connection conn =null;


public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
bookForm myForm = (bookForm) form;
response.setContentType(connTENT_TYPE);
//GET PARAM employeeId
ServletOutputStream out = response.getOutputStream();
BufferedInputStream in = null;

AccessImgByDB.insertImg(myForm);

try{
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@192.168.0.3:1521:EGOV4JS";

Connection conn= DriverManager.getConnection(url, "BOOKMAN", "BOOKMAN");

boolean defaultCommit = conn.getAutoCommit();

conn.setAutoCommit(false);

/* 查询BLOB对象 */
Statement stmt = conn.createStatement();
String sql = "SELECT BOOKIMG FROM BOOK WHERE BOOKNAME='";
sql += myForm.getBookName();
sql += "'";
ResultSet rs = stmt.executeQuery(sql);

rs.next();


oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob("BOOKIMG");
in = new BufferedInputStream(blob.getBinaryStream());
System.out.println(in + " get end");
}
catch (Exception ex)
{

ex.printStackTrace();
}

if (in!=null){

try {
int len;
byte buf[] = new byte[4096];
while ( (len = in.read(buf, 0, 4096)) != -1) {
out.write(buf, 0, len);
}
}
catch (IOException ioe) {
ioe.printStackTrace();
}

}
return null;

}

}

请问这样才能显示出来
...全文
37 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
flyxxxxx 2005-03-15
你应该用另一个Action(response.setContentType("image/jpeg")//如果是gif则是image/gif)或是Servlet来输出图像的数据,因为图像是指向另一个url
回复
相关推荐
发帖
Java EE
创建于2007-09-28

6.6w+

社区成员

J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
申请成为版主
帖子事件
创建了帖子
2005-03-15 02:40
社区公告
暂无公告