0

The environment is MAVEN-based WILDFLY container.

I can retrieve the URI of file as

Foo.class.getClassLoader().getResource("/images/nir.png");

how can I programmatically add a file on that folder?

I did something like this:

Foo.class.getClassLoader().getResource("/text/");
OutputStream stream = new FileOutputStream(newjava.io.File(loader.getFile()+"1.txt"));
//add something on 1.txt, save it on web-inf folder!!

and from web, if I had to connect to this. Why am I not able to do so?

like, to access to server

http://server/text/1.txt

Why doesn't it work this way?

Anthon
  • 51,019
  • 25
  • 150
  • 211
Rockink
  • 180
  • 3
  • 17
  • 1
    Anything under WEB-INF is not directly accessible to the browser. – GriffeyDog May 08 '15 at 13:50
  • wait? I had put static img as WEB-INF/1.png, and I could access that as I want to write on that folder, or create subfolder temporarily, to save some files for a while... – Rockink May 08 '15 at 13:51
  • 1
    It is a best practice NOT to serve content from WEB-INF as that allows attackers to see your code. However, there are certainly servers that allow it. I would consider them misconfigured. – ewramner May 08 '15 at 13:54
  • 1
    Anything you put there will be lost on the next deployment. Don't do this. The resource system should be considered as read-only. – user207421 May 10 '15 at 05:57

1 Answers1

0

Try this code. But it's not recommend

String path = getServletContext().getRealPath("WEB-INF/../");
File file = new File(path);
String fullPathToYourWebappRoot = file.getCanonicalPath();
Janny
  • 623
  • 8
  • 30