属性文件作为web.xml中的init-param [英] Properties file as init-param in web.xml
问题描述
我正在将一个在websphere中托管的基于Jsp-servlet的Java项目迁移到tomcat。以下init-param位于过滤器定义中的web.xml中。我移动了属性文件src文件夹,它是classpath。如何在web.xml中更改以下内容。我可以将属性文件定义为init-param,因为我看到的大多数答案都使用了context-param来定义属性文件。我不认为它是我的一个选项,因为现有的应用程序需要属性文件为init-param。
I am migrating a Jsp-servlet based Java project that was hosted in websphere to tomcat. Following init-param is in web.xml inside a filter definition. I moved the properties file src folder which is classpath. How to change the following in the 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. I dont think its an option to me as the existing application needs the properties file to be init-param.
<init-param>
<param-name>configPath</param-name>
<param-value>/pws/WebSphere/AppServer/properties/fyp/filterConfig/filter.properties</param-value>
</init-param>
我试过
<init-param>
<param-name>configPath</param-name>
<param-value>classpath:filter.properties</param-value>
</init-param>
它不起作用。提前谢谢你,
It did not work.Thank you in advance,
推荐答案
检查您的servlet实现,您将找到如下内容:
Check your servlet implementation,you will find something like the following:
- get来自ServletContext的上下文根路径;
- 追加属性文件路径来自init-param;
- 做一些文件操作
如您所知,您可以将servlet配置为:
As you asked,you can config the servlet as :
<init-param>
<param-name>configPath</param-name>
<param-value>filter.properties</param-value>
</init-param>
然后将您的代码更改为
- 从init-param获取文件名
- 打开流this.getClass()。getClassLoader()。getResourceAsStream(fileName);
- 执行一些文件操作
这篇关于属性文件作为web.xml中的init-param的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!