java - 无法使用存储在数据库中的路径显示图像

标签 java css image jsp servlets

<分区>

enter image description here

    <%@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/

上一篇:html - height div 从上到下页面颜色问题

下一篇:javascript - 根据文本长度动态设置输入宽度

相关文章:

html - 本地文件打开IE

html - 添加填充到文本而不是图像

python - 如何从 opencv 获得准确的 idft 结果?

css - 简单的跨浏览器图像大小调整

java - 用于列映射的 log4j2 模式布局不起作用

java - 如何在java中实现int in/out params

jquery - 无法使用 css 类更改颜色

java - 如何列出不被继承的方法?

java - SparkSQL + Java : Pojo to Tabular Format while working with Datasets

c++ - 在图像上的 OpenCV 中绘制单个轮廓