Java Servlets - Storing a list of values in web.xml (multiple param-value's for single param-name)

后端 未结 4 1945
暗喜
暗喜 2021-02-01 02:41

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

相关标签:
4条回答
  • 2021-02-01 03:21

    Yes, just use delimiters (as no other options available for this):

    <context-param>
        <param-name>validHosts</param-name>
        <param-value>example1.com,example2.com,example3.com</param-value>
    </context-param>
    
    
    
    then simply
    String[] validHosts = param.split(","); // not really much to do
    
    0 讨论(0)
  • 2021-02-01 03:27

    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>
    
    0 讨论(0)
  • 2021-02-01 03:34

    You should use ; to separate them in param-value tag like:

    <context-param>
      <param-name>validHosts</param-name>
      <param-value>example1.com;example2.com;.....</param-value>
    </context-param>
    
    0 讨论(0)
  • 2021-02-01 03:38

    Put each param on its own line. I did the following recently and it works fine:

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/spring-beans.xml
            /WEB-INF/security-config.xml    
        </param-value>
    </context-param>
    
    0 讨论(0)
提交回复
热议问题