<分区>
<分区>
<%@page import="java.sql.*"%>
<%@page import="com.binod.db.DBConnection"%>
<jsp:include page="header.jsp"/>
<center>
<div class="content">
<table border="1" cellpadding="5" class="full">
<tr>
<td>Cat_id</td>
<td>cat_name</td>
<td>
Cat_Path
</td>
</tr>
<%
ResultSet rs;
DBConnection db=new DBConnection();
db.open();
String query="Select * from `category`";
PreparedStatement preparedStatement =db.getPreparedStatement(query);
rs=preparedStatement.executeQuery();
while(rs.next()){
int cat_id=rs.getInt("cat_id");
String cat_name=rs.getString("cat_name");
String cat_path=rs.getString("cat_image");
System.out.println(cat_path);
%>
<tr>
<td><%=cat_id %></td>
<td> <%= cat_name %></td>
<td class="Images"><img src="<%= cat_path%>" alt="Image not found"/></td>
</tr>
<%
}
%>
</table>
</div>
</center>
<jsp:include page="footer.jsp"/>
我的控制台输出:存储在数据库中的图像路径
C:\Users\Binod\workspace\shop\Pictures\Category\bbb.jpg C:\Users\Binod\workspace\shop\Pictures\Category\bbb.jpg C:\Users\Binod\workspace\shop\Pictures\Category\Screenshot(5).png C:\Users\Binod\workspace\shop\Pictures\Category\Screenshot(5).png C:\Users\Binod\workspace\shop\Pictures\Category\Screenshot(5).png C:\Users\Binod\workspace\shop\Pictures\Category\Screenshot(5).png C:\Users\Binod\workspace\shop\Pictures\Category\Screenshot(5).png C:\Users\Binod\workspace\shop\Pictures\Category\Screenshot(6).png
最佳答案
也许你应该避免使用图像或文件的物理路径。
只需将资源(如图像、文件)放在您正在工作的元素中即可。
并将图片的相对路径保存到数据库中。
关于java - 无法使用存储在数据库中的路径显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42721080/