-1

I'm building a servlet that uses a RequestDispatcher to load a html page for the log in.

The html is in /WEB-INF/templates/main.html

I'm trying to load an image for that html file which is on /WEB-INF/resources/image.jpg

I've tried with <img src="/WEB-INF/resources/image.jpg, and also without the slash before WEB-INF.

I tried with <img src="../resources/image.jpgas well.

None seems to work, how can I do this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Jorge Barroso
  • 1,878
  • 1
  • 13
  • 14
  • Use the classloader because the code that you have used didn't work and you can't do anything with it. – Roman C Oct 07 '16 at 19:54
  • can you give me an example of what you mean? – Jorge Barroso Oct 07 '16 at 19:56
  • google for examples, I won't give you any example. Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. – Roman C Oct 07 '16 at 19:57

3 Answers3

2

You can't do this.

The problem is that the image is being loaded by the browser, not the application. And nothing outside the internals of the application can access anything in the WEB-INF directory.

So, you simply need to move the image someplace else.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Will Hartung
  • 115,893
  • 19
  • 128
  • 203
1

Don't put resources exposed to the outside world (outside your server) under the WEB-INF folder. For static resources, such as images, Javascript files etc... use a directory outside of WEB-INF.

Mechkov
  • 4,294
  • 1
  • 17
  • 25
1

WEB_INF is not public web space, so ant files under WEB_INF can't be accessed by outside web applications like any browser or any other app that is calling that URL. However it can be read from the files in your app server (internal files).

Images in <img src=""> tag are loaded by browser not by your application, so you have no other option other than to move all your images, css, and js files outside WEB-INF.

Saurabh Singh
  • 381
  • 5
  • 15