属性文件作为web.xml中的init-param [英] Properties file as init-param in web.xml

查看:556
本文介绍了属性文件作为web.xml中的init-param的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个在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:


  1. get来自ServletContext的上下文根路径;

  2. 追加属性文件路径来自init-param;

  3. 做一些文件操作

如您所知,您可以将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>

然后将您的代码更改为


  1. 从init-param获取文件名

  2. 打开流this.getClass()。getClassLoader()。getResourceAsStream(fileName);

  3. 执行一些文件操作

这篇关于属性文件作为web.xml中的init-param的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆