我有一個bytearray圖像。如何在jsp中顯示圖像?
我需要顯示在JSP頁面中的JPG格式圖片,並同時點擊圖像,我可以將圖像下載到我的電腦:
我從我的MySQL數據庫加載圖像作爲字節數組..
我的代碼是
ResultSet res = statement.executeQuery("SELECT * FROM
upload_data where user_id = "+userID);
while (res.next()) {
contactDetails = new ContactDetails();
contactDetails.setContactPhoto(res.getBytes("photo"));
byteArrayBackToImage1(res.getBytes("photo"));
contactsList.add(contactDetails);
}
public void byteArrayBackToImage1(byte[] imageInByte){
try{
Random rand = new Random();
int numNoRange = rand.nextInt();
String number = String.valueOf(numNoRange);
//convert byte array back to BufferedImage
InputStream in = new ByteArrayInputStream(imageInByte);
BufferedImage bImageFromConvert = ImageIO.read(in);
System.out.println("bImageFromConvert : "+bImageFromConvert);
/*ImageIO.write(bImageFromConvert, "jpg",
new File("c:\\"+number+".jpg")); */
}catch (Exception e) {
// TODO: handle exception
}
我需要顯示在JSP中的圖像作爲
例如:image.jpg的 image2.jpg
,並通過點擊image.jsp,我可以下載圖片並保存到我的電腦
請幫
迴應*我有一個圖像清單,對應於特定的ID *的數據庫,您需要唯一標識圖像。 – 2011-03-09 10:05:13
相關:http://stackoverflow.com/questions/2340406/retrieve-multiple-images-from-mysql/2341322#2341322 – BalusC 2011-03-09 12:31:44
@ jigar @BalusC這將是一個很大的幫助,如果你可以提供一些輸入http:// stackoverflow.com/questions/11124540/some-questions-related-to-implementation-of-image-inside-email-signature。提前致謝。 – 2012-06-20 18:01:17