【问题标题】:i want to retrieve images from imagepaths stored in db in jsp我想从 jsp 中存储在 db 中的图像路径中检索图像
【发布时间】:2012-02-28 11:36:11
【问题描述】:

我正在使用 jsp 文件,我想检索图像

问题是我已经存储了图像路径,我想从该图像路径中检索图像到 jsp 页面

这怎么可能? 我正在使用 ms-access 数据库。

Connection con = null;
    ResultSet rst = null;
    Statement st = null;

    try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            con=DriverManager.getConnection("jdbc:odbc:register");
            st=con.createStatement();
            rst = st.executeQuery("select * from productregistration");
                while(rst.next())
                {
                    %>
               <img src="<%=rst.getString(1)%>"/>
                    <%

                }
               }
    catch (Exception ex) {
        ex.printStackTrace();
    }

【问题讨论】:

  • 你想用那个代码做什么?连接未打开。 select * 是一件坏事。 getString(1) 是一件坏事。您必须将图像路径添加到img 标签。
  • 但是当我只写 rst.getString() 时,会检索存储在数据库中的所有图像路径,但是当我将这些值放入 src 时,我什么也得不到
  • ohkk 我得到了答案...它实际上是我有商店的相对路径,而不是我将只存储图像名称然后获取它......它称为实际路径

标签: jsp ms-access jdbc


【解决方案1】:

无法获取相关路径,请使用绝对路径

【讨论】:

    猜你喜欢
    • 2017-09-13
    • 1970-01-01
    • 1970-01-01
    • 2016-12-26
    • 2020-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多