How to insert images in JSP?


I have been trying to put a simple image in a JSP project for more than 3 hours, I am just learning how to handle this, and I need to put an image that I have saved in a directory of my pc, I have tried to do it as if programming a html normally , but in JSP some things change and the normal way of doing it does not work, how can I put it in the JSP html that is stored in my PC's Desktop? I have searched so much but no help helps me because I do not understand anything that they explain or they go to databases that I am not using that. I have this <img src= id="imagen"> , what should I put in src so that the image is inserted correctly? Please, short explanation because JSP was never explained to me in classes and they gave me this job, and I have only learned the basics from YouTube. Use GlassFish as server

asked by Christian H 16.12.2018 в 05:34

1 answer


to be able to insert an image in a jsp page, you can do the following:

1) Create a directory or folder for images within the project:

As you can see there is a directory called " img " there would be the images.

2) Taking into account the previous structure, in the jsp the image would be inserted in the following way:

<img src="img/imagen.png" id="miImagen">

Note that " image.png " must be inside the " img " directory and the jsp file should be on the outside. The src attribute defines the path of the image, on the other hand the attribute "id" represents a unique identification value for the element.


answered by 08.01.2019 в 21:05