简体   繁体   English

属性文件作为web.xml中的init-param

[英]Properties file as init-param in web.xml

I am migrating a Jsp-servlet based Java project that was hosted in websphere to tomcat. 我正在将一个在websphere中托管的基于Jsp-servlet的Java项目迁移到tomcat。 Following init-param is in web.xml inside a filter definition. 以下init-param位于过滤器定义中的web.xml中。 I moved the properties file src folder which is classpath. 我移动了属性文件src文件夹,它是classpath。 How to change the following in the web.xml. 如何在web.xml中更改以下内容。 Can I define properties file as init-param because most of the answers I saw has used context-param to define properties file. 我可以将属性文件定义为init-param,因为我看到的大多数答案都使用了context-param来定义属性文件。 I dont think its an option to me as the existing application needs the properties file to be init-param. 我不认为它是我的一个选项,因为现有的应用程序需要属性文件为init-param。

<init-param>
    <param-name>configPath</param-name>
    <param-value>/pws/WebSphere/AppServer/properties/fyp/filterConfig/filter.properties</param-value>
</init-param>

I tried 我试过了

<init-param>
      <param-name>configPath</param-name>
      <param-value>classpath:filter.properties</param-value>
</init-param>

It did not work.Thank you in advance, 它没用。谢谢你提前,

Check your servlet implementation,you will find something like the following: 检查您的servlet实现,您将找到类似以下内容:

  1. get the context root path from ServletContext; 从ServletContext获取上下文根路径;
  2. append the property file path get from init-param; 从init-param追加属性文件路径get;
  3. do some file operation 做一些文件操作

As you asked,you can config the servlet as : 正如您所问,您可以将servlet配置为:

    <init-param>
      <param-name>configPath</param-name>
      <param-value>filter.properties</param-value>
   </init-param>

then change your code to 然后将您的代码更改为

  1. get the file name from init-param 从init-param获取文件名
  2. open the stream this.getClass().getClassLoader().getResourceAsStream("fileName"); 打开流this.getClass()。getClassLoader()。getResourceAsStream(“fileName”);
  3. do some file operation 做一些文件操作

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

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