Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If it are application wide constants, just put them in the application scope during application startup. You can use the <code>init()</code> method of an arbitrary servlet for this or, better, a <code>ServletContextListener</code>.</p> <pre><code>@WebListener public class Config implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent event) { Map&lt;String, String&gt; creditCardTypes = new LinkedHashMap&lt;String, String&gt;(); creditCardTypes.put("M0", "MasterCard"); creditCardTypes.put("D0", "Discover"); // ... event.getServletContext().setAttribute("creditCardTypes", creditCardTypes); } // ... } </code></pre> <p><em>(note that I used <code>LinkedHashMap</code> as it maintains insertion order in contrary to <code>HashMap</code>)</em></p> <p>This way it's available as <code>${creditCardTypes}</code> by EL in any JSP. You can then use <a href="https://stackoverflow.com/tags/jstl/info">JSTL</a> <code>&lt;c:forEach&gt;</code> to iterate over it. It also supports iterating over a <code>Map</code> and each iteration will give a <a href="http://download.oracle.com/javase/6/docs/api/java/util/Map.Entry.html" rel="nofollow noreferrer"><code>Map.Entry</code></a> back which in turn has <code>getKey()</code> and <code>getValue()</code> methods which are accessible in EL as well.</p> <pre><code>&lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt; ... &lt;select id="creditCardType" title="select card type" name="creditCardType"&gt; &lt;c:forEach items="${creditCardTypes}" var="creditCardType"&gt; &lt;option value="${creditCardType.key}"&gt;${creditCardType.value}&lt;/option&gt; &lt;/c:forEach&gt; &lt;/select&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload