开发者

Referencing to a file inside war

I have source folder test, in what there is package Resources.Data, that among others contains files data[0].xml, that I want to reference in webpage (it i开发者_如何学Cs acceptable that all files in that directory are visible). After I build the war, files are in war\WEB-INF\classes\Resources\Data. I can make a manual duplicate, to top level, but it seems a dumb thing to do.

My question is: How do I refence data[0].xml or is duplicate 'not a dumb thing to do'?


If you need the resource to be visible to the browser, then don't put it under /WEB-INF. Files in there are not visible.

It looks like you need to chance your build so that those resources are stored elsewhere, rather than copying them around.


You can read the file directly in the war.

InputStream in = MyClass.class.getResourceAsStream("/Resources/Data/data[0].xml");

You can then do whatever you need with the InputStream. This should occur inside of Java code, not in JSP.

You should consider storing this above the WEB-INF folder, though, so that it can be served directly. Duplicating the file is unnecessary.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜