0

I have a small java web app and want to have access to some resources during validation.
I know how to do it in servlet since I can use ServletContext, but I don't know how to access it from my validator code. Resources can be stored in WEB_INF folder or inside packages, but when I tried Class.class.getResourcesAsStream() it always returned null.
I feel like I'm doing something wrong, but cannot get what is.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Chechulin
  • 2,426
  • 7
  • 28
  • 35

1 Answers1

0

Well alternatively you can get a file then put an InputStream on it

String path = "resources/images/image.png"
ServletContext ctx = (ServletContext) FacesContext.getCurrentInstance()
                .getExternalContext().getContext();
    String  realPath = ctx.getRealPath("/");
File file = new File(realPath + path);

if the file is in a package then the path would look like

String path= "WEB-INF/classes/package/file"
Ced
  • 15,847
  • 14
  • 87
  • 146