How do I show an image that is in the database using jsp?

Asked

Viewed 289 times

1

Well, here’s the thing. I’m using JSP, SERVLET and Mysql to insert images into my project, it turns out I just keep the image path in the database, and then call this path to show the image. Then the problem happens:

<%
        ArrayList<Fotos> lista = new ArrayList<Fotos>();
        try {
            Fotos f = new Fotos();
            lista = f.listar();
        } catch (Exception e) {
            out.print("Erro:" + e);
        }

        for (Fotos fl : lista) {

    %>
    <p><%=fl.getId()%><p>
        <img src="img/<%fl.getLink()%>">
<td><a href="alterar_foto.jsp?id=<%=fl.getId()%>">alterar</a>/<a href="#" onclick="excluir('<%=fl.getLink()%>', '<%=fl.getId()%>');">excluir</a>
    <%
        }
    %>

The image path on my computer is: C: Users Gabriel Documents Engatfitoriginal web img

only it does not show on the listing page:

É assim que o link aparece no hmtl

Someone knows how to do?

1 answer

0


Opa, I recommend you save only the file name in the BD and in the code make a concatenation of the project path + result of the BD query that will return the name of the photo.

Ex: In BD you save original.jpg and in JSP you return the project path and concatenate with the result of the database query.

Final Javascript should only process /web/img/photo.jpg instead of C:/Users/Gabriel/Documents/Engatfitoriginal/web/img/photo.jpg

  • True, it worked. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.