Sharing a configuration parameter among servlets

Is there a way that two (or more) servlets can share a configuration parameter declared once in web.xml?

Looked here , but it doesn't seem to be the answer.

The practical example is pretty simple: I have two servlets: one uploads files to a directory, and the other uploads them. I would be happy to enlist the directory / path only once in web.xmlorder to avoid ambiguity / confusion.

+3
source share
2 answers

Yes, add <context-param>to yours web.xml, for example.

<context-param>
   <param-name>myParam</param-name>
   <param-value>Some value</param-value>
</context-param>

This is tied to webapp as a whole, and not to individual servlets.

getInitParameter(...) ServletContext (, , getServletContext() ).

+3

<env-entry> web.xml:

  <env-entry>
    <description>This is the address of the SMTP host that shall be used to send mails
    </description>
    <env-entry-name>smtp.mailhost</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>mailhost</env-entry-value>
</env-entry>

JNDI ( , ) WAR/EAR. <env-entry-value> , - , .

0

All Articles