<img src="images\upload\ <%=rs.getString("content").trim()%>" border="0">
图片的路径是C:\Tomcat 5.0\webapps\jizhetuan\images\upload\9186890_m.jpg
在数据库里存放的content字段为9186890_m.jpg
怎么图片显示不出来,请高手指点
图片的路径是C:\Tomcat 5.0\webapps\jizhetuan\images\upload\9186890_m.jpg
在数据库里存放的content字段为9186890_m.jpg
怎么图片显示不出来,请高手指点
-----------------加上绝对路径看看:<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
就只有<img src=" <%="/images/upload/"+rs.getString("content").trim()%>" border="0">
"图片显示不出来那个地方会出现一个红叉,在红叉上点右键看看属性,看看url对不对"用这个方法看看
生成的url和预期的差距,然后拼出url字符串。
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
就只有 <img src=" <%="/images/upload/"+rs.getString("content").trim()%>" border="0">
要把这个数据解析成字节数组,然后用outStream,write出来。如下:public static void readPhoto(Blob blob,HttpServletResponse res) throws SQLException, IOException{
ServletOutputStream out = res.getOutputStream();
if(blob!=null && blob.length()!=0){
InputStream in = blob.getBinaryStream();
byte [] buf=new byte[1024000];
int len;
while((len=in.read(buf))!=-1){
out.write(buf,0,len);
}
in.close();
}
out.close();
}
问题解决了.