在 servlet 中读取/写入文本文件,该文件应该存储在 JBoss 中的什么位置? [英] Reading/writing a text file in a servlet, where should this file be stored in JBoss?
问题描述
我在 JBoss 中部署了 servlet.我想根据客户端输入将数据读/写到文本文件中.这个文本文件应该放在 JBoss 目录结构中的什么位置?
I have servlet deployed in JBoss. I want to read/write data into a text file based on the client input. Where should this text file be put in the JBoss directory structure?
推荐答案
/data
目录就是用来解决这个问题的.
There the /data
directory is for.
它的绝对路径可以通过 jboss.server.data.dir
系统属性获得.
Its absolute path is available by the jboss.server.data.dir
system property.
File dataDir = new File(System.getProperty("jboss.server.data.dir"));
File yourFile = new File(dataDir, "filename.ext");
// ...
另见:
- JBoss Wiki - JBoss 属性
请注意,您通过这种方式将 Web 应用程序代码紧密耦合到特定服务器.如果您想更改服务器,请记住将上述代码也更改为新服务器支持(或不支持)的任何内容.
Note that you're this way tight-coupling the web application code to a specific server. If you ever want to change servers, keep in mind to change the above code as well to whatever the new server supports (or not).
这篇关于在 servlet 中读取/写入文本文件,该文件应该存储在 JBoss 中的什么位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!