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

1

Well, here's the thing. I'm using JSP, SERVLET and MySQL to insert images into my project, I just happen to save the image path in the database, and then call that path to show the image. Hence the problem:

<%
        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 path of the image on my computer is: C: \ Users \ Gabriel \ Documents \ EngatFitOriginal \ web \ img

It just does not show on the list page:

Does anyone know how to do it?

    
asked by anonymous 19.11.2017 / 20:02

1 answer

0

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

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

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

    
19.11.2017 / 21:59