我試圖從數據庫中獲取圖像,我能夠獲取圖像,現在我想要顯示該圖像到jsp頁面。我正在使用hibernate和struts。我有動作類和一個hibernate持久類(POJO)。無法使用休眠和struts從數據庫中顯示圖像jsp使用休眠和struts
Action類是SportsAction
package action;
@Result(location="sports-success.jsp")
public class SportsAction extends ActionSupport{
public List<SportsSetterAndGetter> l;
public List<SportsSetterAndGetter> getL() {
return l;
}
public void setL(List<SportsSetterAndGetter> l) {
this.l = l;
}
private byte[] pic;
public byte[] getPic() {
return pic;
}
public void setPic(byte[] pic) {
this.pic = pic;
}
@Action(value="sports")
@Override
public String execute() throws Exception {
Session session= new AnnotationConfiguration().configure().buildSessionFactory().openSession();
Transaction t= session.beginTransaction();
l=session.createCriteria(SportsSetterAndGetter.class).list();
Iterator itr1=l.iterator();
SportsSetterAndGetter s=new SportsSetterAndGetter();
while (itr1.hasNext()) {
s=(SportsSetterAndGetter)itr1.next();
System.out.println("values are"+s.getSid());
System.out.println(s.getName());
System.out.println(s.getRate());
System.out.println(s.getStatus());
System.out.println(s.getStype());
pic=s.getImage();
}
return "success";
}
}
在Jsp頁面
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<s:iterator value="l">
<s:property value="sid" />
<h1><s:property value="name" /></h1>
<h3><s:property value="rate" /></h3>
<h3><s:property value="status" /></h3>
<s:property value="stype" />
<img src="<s:property value="image" />" />
</s:iterator>
</body>
</html>
我正在從數據庫中這個值,但我無法獲取圖像。我應該寫什麼來獲得形象。
你是從數據庫讀取圖像?如果是這樣,爲什麼你要保留這一行
「/>。圖像是否可以在路徑」image「的某個目錄下物理使用?您應該使用byte []值來獲取圖像 –
@ShaileshSaxena是圖像從數據庫中獲取。如何使用byte []在jsp頁面中獲取圖像,在
圖像是hibernate setter和getter中byte []的名稱 – user3359130在您的SportsAction類中, ]? –