سؤال

I have a war file that I have deployed which contains an images folder in the WEB-APP directory. I tried accessing the images stored in the folder using "localhost:8080/testapp/images/image1.jpg" but I am getting a 404 response. Can someone please help me with this? Thanks in advance.

هل كانت مفيدة؟

المحلول

Your images directory needs to be a sibling of WEB-INF, not a child of it. Try this:

your-war-file.war
  |-images/
  |   |-image1.jpg
  |   |-image2.jpg
  |   `-image3.jpg
  |-WEB-INF/
  |   |-classes/
  |   |-lib/
  |   `-web.xml
  |-index.html
  `-404.html

نصائح أخرى

Assuming you have your folder 'images' in the base directory for this web app (on the same level as 'META-INF' and 'WEB-INF' catalogs), the path seems correct. Maybe check that you haven't put 'images' folder inside 'WEB-INF' where it is not accessible? If that doesn't work, try accessing some other file inside your web app to check that it was deployed on server.

Clients may not directly access artifacts under WEB-INF.

Put them in a location directly accessible if you're not streaming them from an app endpoint.

how to read from path ? use ("."+File.seperator+"some else") path of File for current path into your code or html file

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top