I have a java web app on a wildfly server, and in a different folder on this server there are multiple photos that my app needs to read.
They're employee photos and each one has the employee ID as the name. In my app I read all employee info from the database (except the photo) and they are grouped into different departments.
I need to read the certain employee photos (from the server folder) according to the employee ID's that are in certain departments and display them in a JSP (where the rest of the employee info is displayed).
Can anyone help with how I am best doing this in a servlet? I am able to read one sample photo using the code below but am struggling to read more than one-
Below is the code from my servlet that handles the employee info (the empID's are in the employees arraylist)
Do I load all images from the folder in a servlet and then in my jsp (where I get the empID) handle the linking of the photo with the empID? Or do I handle this all in a servlet? (Sorry I am very lost and new to this)
Assuming that the directory containing the images is not directly accessible via the web server, you would need a servlet that streams the images. It would take the employee ID as a parameter, and use that to construct the path to the image file. Your doGet method is already mostly there, except for the parameter.
You would need to get only the image you intend to serve. Whether you need to loop through all employees depends on how the image file names are arranged. If the images are arranged by ID you'll know the image path just by looking at the ID. If, OTOH, the file name is dependent on some other piece of information that is associated with the employee, you may have to loop through them in order to find the image path.