Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6145967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:52:25+00:00 2026-05-23T18:52:25+00:00

In a jsp page ,I am presenting the customer with drop down lists to

  • 0

In a jsp page ,I am presenting the customer with drop down lists to select creditcardtype,expiration month,expiration year of credit card.
I am looking at ways the necessary strings for this can be put ,other than hardcoding them in html.

thanks

mark

<tr>
<td>
    <select id="creditCardType" title="select card type" name="creditCardType">
        <option value="M0">MasterCard</option>
        <option value="D0">Discover</option>
        <option value="J0">JCB</option>
        <option value="I0">Diners Club</option>
        <option value="A0">American Express</option>
        <option value="V0">Visa</option>
        <option value="V">Amazon.com Visa</option>
        <option value="G21">Amazon.com Store Card</option>
    </select>
</td>
</tr>
<tr>
<td>Expiration Date</td>
<td> 
                     <select id="cardexpiryMonth" name="cardexpiryMonth">
                        <option value="01" selected="selected">01</option>
                        <option value="02" >02</option>
                        <option value="03" >03</option>
                        <option value="04" >04</option>
                        <option value="05" >05</option>
                        <option value="06" >06</option>
                        <option value="07" >07</option>
                        <option value="08" >08</option>
                        <option value="09" >09</option>
                        <option value="10" >10</option>
                        <option value="11" >11</option>
                        <option value="12" >12</option>
                      </select>
</td>
<td>
                    <select id="cardexpiryYear" name="cardexpiryYear">
                        <option value="2011" >2011</option>
                        <option value="2012" selected="selected">2012</option>
                        <option value="2013" >2013</option>
                        <option value="2014" >2014</option>
                        <option value="2015" >2015</option>
                        <option value="2016" >2016</option>
                        <option value="2017" >2017</option>
                        <option value="2018" >2018</option>
                        <option value="2019" >2019</option>
                        <option value="2020" >2020</option>
                        <option value="2021" >2021</option>
                        <option value="2022" >2022</option>
                        <option value="2023" >2023</option>
                        <option value="2024" >2024</option>
                        <option value="2025" >2025</option>
                        <option value="2026" >2026</option>

                        <option value="2027" >2027</option>
                        <option value="2028" >2028</option>
                        <option value="2029" >2029</option>
                        <option value="2030" >2030</option>
                        <option value="2031" >2031</option>
                      </select>
</td>
</tr>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:52:26+00:00Added an answer on May 23, 2026 at 6:52 pm

    If it are application wide constants, just put them in the application scope during application startup. The application scope is represented by the object being an attribute of ServletContext. See also How do servlets work? Instantiation, sessions, shared variables and multithreading

    CDI available?

    If CDI happens to be available in your environment (i.e. you’re running a normal JEE server such as WildFly, Payara, TomEE, etc), then just use an @ApplicationScoped bean instead of a ServletContextListener.

    @Named @ApplicationScoped
    public class Data {
    
        private Map<String, String> creditCardTypes;
    
        @PostConstruct
        public void init() { 
            creditCardTypes = new LinkedHashMap<String, String>();
            creditCardTypes.put("M0", "MasterCard");
            creditCardTypes.put("D0", "Discover");
            // ...
        }
    
        public Map<String, String> getCreditCardTypes() {
            return creditCardTypes;
        }
    }
    

    (note that I used LinkedHashMap as it maintains insertion order in contrary to HashMap)

    This way it’s available as ${data.creditCardTypes} by EL in any JSP. You can then use JSTL <c:forEach> to iterate over it. It also supports iterating over a Map and each iteration will give a Map.Entry back which in turn has getKey() and getValue() methods which are accessible in EL as well.

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    ...
    <select id="creditCardType" title="select card type" name="creditCardType">
        <c:forEach items="${data.creditCardTypes}" var="creditCardType">
            <option value="${creditCardType.key}">${creditCardType.value}</option>
        </c:forEach>
    </select>
    

    No CDI available?

    If CDI is not available (i.e. you’re not running a normal JEE server, such as Tomcat, Jetty, Undertow, etc, and you don’t want to install CDI for some reason), then you can use the init() method of an arbitrary servlet or, better, a ServletContextListener.

    @WebListener
    public class Data implements ServletContextListener {
    
        private Map<String, String> creditCardTypes;
    
        @Override
        public void contextInitialized(ServletContextEvent event) { 
            creditCardTypes = new LinkedHashMap<String, String>();
            creditCardTypes.put("M0", "MasterCard");
            creditCardTypes.put("D0", "Discover");
            // ...
    
            event.getServletContext().setAttribute("data", this);
        }
    
        public Map<String, String> getCreditCardTypes() {
            return creditCardTypes;
        }
    }
    

    This way it’s also available as ${data.creditCardTypes} by EL in any JSP.

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    ...
    <select id="creditCardType" title="select card type" name="creditCardType">
        <c:forEach items="${data.creditCardTypes}" var="creditCardType">
            <option value="${creditCardType.key}">${creditCardType.value}</option>
        </c:forEach>
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On a JSTL/JSP page, I have a java.util.Date object from my application. I need
In a JSP page, I created a <h:form enctype=multipart/form-data> with some elements: <t:inputText> ,
Writing a JSP page, what exactly does the <c:out> do? I've noticed that the
I have this simple Jsp page: <%@ page language=java import=java.awt.Color%> <% Color background =
I have a jsp page with two radio tags. The page contains a struts2
I've got a JSP page with a piece of Javascript validation code which limits
In a JSP page(index.jsp): ${requestContext.requestURL} is the URL just shows the expression itself. It
I have a jsp page which should load a popup using ajax. The content
I am having a JSP page, where i am dynamically creating a Table data.
In a JSP page, there is such code: <jsp:useBean id=checklog class=com.google.admin.guard.CheckLogBean scope=session /> and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.