1 图片已经上传,数据库也获得正确的图片地址
2 在页面上也可以查看到正确的图片地址
3 重新启动一下tomcat 图片就可以显示
这是什么问题
前端页面
<body bgcolor="white">
<%
response.setHeader("Pragma", "No-Cache");
response.setHeader("Cache-Control", "No-Cache");
response.setDateHeader("Expires", 0);
BookDao bookDao = new BookDao();
List<Books> list = new ArrayList<>();
List item = new ArrayList();
list = bookDao.listBookInfo();
%>
<%
for (Books books : list
) {
%>
<table>
<tr>
<td rowspan="4"><img alt="图片不存在" src="<%=books.getImgPath()%>" width="130px" height="180px"></td>
</tr>
<tr>
<td><%=books.getBookname() + "( 书号:" + books.getBookid() + ")"%>
</td>
</tr>
<tr>
<td><%=books.getWriter()%>
</td>
<td><%=books.getCbs()%>
</td>
</tr>
<tr>
<td><%=books.getItems()%>
</td>
</tr>
</table>
<hr>
<%
}
%>
Dao
public List<Books> listBookInfo() {
List<Books> list = new ArrayList();
try {
String sql = "SELECT * FROM books WHERE isLend=1";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()) {
Books books = new Books();
books.setBookid(rs.getLong("bookId"));
books.setBookname(rs.getString("bookName"));
books.setCbs(rs.getString("cbs"));
books.setWriter(rs.getString("writer"));
books.setIslend(rs.getLong("isLend"));
books.setItems(rs.getString("items"));
books.setDate(rs.getTimestamp("date"));
books.setImgPath(rs.getString("imgpath"));
list.add(books);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
按照你的说法有一种可能性,你的图片还被存在内存中。
比如你的输出流是缓存的,但你的代码中既没有flush也没有close,然后重启导致了强制的flush。