0

In my bean I am getting the URL of an image like this:

ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
URL url = ec.getResource("/myImageDirectory/image.png");

How can I do this in a HttpServlet?

I tried the following, but it did not work:

ServletContext sc = getServletContext();
URL url = sc.getResource("/myImageDirectory/image.png");

The HttpServlet is in the same application as the bean.

sinclair
  • 2,812
  • 4
  • 24
  • 53

1 Answers1

1
 getServletContext().getRealPath("/")+"/myImageDirectory/image.png";

The "/" represents the web content root.

More

Community
  • 1
  • 1
SatyaTNV
  • 4,137
  • 3
  • 15
  • 31