Java Servlets - 在web.xml中存储值列表(单个param-name的多个param-value) [英] Java Servlets - Storing a list of values in web.xml (multiple param-value's for single param-name)

查看:112
本文介绍了Java Servlets - 在web.xml中存储值列表(单个param-name的多个param-value)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个需要加载配置信息的servlet。我需要的部分配置信息是字符串列表(特别是主机名和/或URL列表)。

I'm creating a servlet that needs to load configuration information. Part of the configuration information I need is a list of Strings (specifically, a list of hostnames and/or URLs).

我希望将这些信息存储在我的servlet中web.xml文件(所以我不必编写自己的解析器)作为context-param或init-param;基本上是单个param-name的多个param-value。

I was hoping to store this information in my servlet's web.xml file (so I don't have to write my own parser) as either a context-param or init-param; essentially multiple param-value's for a single param-name.

我想要的例子:

<context-param>
    <param-name>validHosts</param-name>
    <param-value>example1.com</param-value>
    <param-value>example2.com</param-value>
    <param-value>example3.com</param-value>
</context-param>

我的初步研究似乎表明这是不可能的 - 只有一个参数 - 任何param-name的值(在context-param或init-param中)。

My initial research seems to indicate this is not possible--that there can only be a single param-value for any param-name (within either context-param or init-param).

我知道我可以在单个param-value中使用分隔列表,但是如果我还想使用web.xml,那真的是我唯一的选择吗?我应该停止抱怨并编写自己的配置文件解析器吗?

I know I could just use a delimited list within a single param-value, but is that really my only option if I still want to use web.xml? Should I just stop whining and write my own config file parser?

推荐答案

Servlet规范说你只能有一个任何上下文参数的值。因此,您只能使用分隔列表。

Servlet spec says that you can have only one value for any context parameter. So, you are left with going with delimited list only.

<context-param>
  <param-name>validHosts</param-name>
  <param-value>example1.com,example2.com,.....</param-value>
</context-param>

这篇关于Java Servlets - 在web.xml中存储值列表(单个param-name的多个param-value)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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