日期:2014-05-17 浏览次数:20744 次
private String book_id;
private BookService bookService;
private HttpServletResponse response;
private Book book;
private ServletOutputStream out; // 二进制流可以直接在jsp页面显示
public String execute() throws Exception {
//getBookDetails是从数据库中得到一个书本所有信息,当然包括图片信息,图片是Blob类型
if (!getBookDetails()) {
return "failed";
}
getImage();
return "success";
}
public String getImage() {
Blob image = book.getImage();
try {
InputStream in = image.getBinaryStream();
out = response.getOutputStream();
byte b[] = new byte[in.available()];
in.read(b);
out.write(b);
out.flush();
out.close();
in.close();
} catch (SQLException e) {
e.printStackTrace();
return "error";
} catch (IOException e) {
e.printStackTrace();
return "error";
}
return "show";
}
private boolean getBookDetails() {
book = bookService.getBookByBook_Id(book_id);
if (book == null)
return false;
return true;
}