引用 war 内的文件
我有源文件夹 test
,其中有包 Resources.Data
,其中包含文件 data[0].xml
,我想要在网页中引用(该目录中的所有文件都可见是可以接受的)。构建 war 后,文件位于 war\WEB-INF\classes\Resources\Data
中。我可以手动复制到顶级,但这似乎是一件愚蠢的事情。
我的问题是:如何引用 data[0].xml
或重复“这不是一件愚蠢的事情”?
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 is 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'?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您需要资源对浏览器可见,则不要将其放在
/WEB-INF
下。里面的文件不可见。看起来您需要尝试构建,以便将这些资源存储在其他地方,而不是四处复制它们。
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.
你可以直接在war中读取该文件。
然后,您可以使用
InputStream
执行您需要的任何操作。这应该发生在 Java 代码中,而不是 JSP 中。不过,您应该考虑将其存储在 WEB-INF 文件夹上方,以便可以直接提供服务。无需复制该文件。
You can read the file directly in the war.
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.