简体   繁体   English

如何将db目录添加到web.xml

[英]how to add db directory to web.xml

I have a java web app configured with apache v9.0 and eclipse IDE. 我有一个配置了apache v9.0和eclipse IDE的Java Web应用程序。 What I need is to keep my database in C:\\db so It cannot be access directly from outside and should be away from my webapp project directory. 我需要将数据库保存在C:\\db这样它就不能直接从外部访问,而应该远离我的webapp项目目录。 What I don't is how to let my web app know that if a user request for a file it should go and check it in my C:\\db and reply back with the file. 我不想要的是如何让我的Web应用程序知道,如果用户请求文件,则应去我的C:\\db文件中检查它,然后用文件答复。

Based in my research, some was saying to specify my directory in my webapp web.xml file and others was saying I need to specify it in my tomcat/conf/server.xml file. 根据我的研究,有人说要在我的webapp web.xml文件中指定目录,而有人说我需要在tomcat / conf / server.xml文件中指定目录。

I'd really appreciate if somebody tell me what to do? 如果有人告诉我该怎么办,我将不胜感激。

Try adding your database path C:\\db as JVM argument and accessing it in application. 尝试将数据库路径C:\\dbJVM argument ,然后在应用程序中访问它。 you may try this as two ways either set as system property and access when it required or set as JVM argument and access it. 您可以通过两种方法尝试将其设置为系统属性并在需要时进行访问,或者设置为JVM参数并对其进行访问。

  1. SetSystemProperties SetSystemProperties
    System.setProperty("database", "C:\\\\db"); . . access it as and when required String databasepath= System.getProperty("database");

  2. Setting as JVM Arguments. 设置为JVM参数。

    1. Double Click on your tomcat server on which your web application is present. 双击您的Web应用程序所在的tomcat服务器。
    2. Click on "Open launch configuration" link and go to Arguments Tab. 单击“打开启动配置”链接,然后转到“参数”选项卡。
    3. in vmArguments apend the entry like below. 在vmArguments中添加如下所示的条目。
      -Ddatabase="C:\\db"
    4. A -D is placed in front of each system property that we are passing in as a VM argument, and following this is an equal sign followed by the value of that system property . -D放在我们作为VM参数传入的每个系统属性的前面,其后是equal sign后跟该system property的值。
    5. And access it in your project where its required like below. 并在需要的项目中访问它,如下所示。
      String databasepath= System.getProperty("database");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM