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 6227693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:15:58+00:00 2026-05-24T09:15:58+00:00

I have a EnumMap: EnumMap<Gender, Integer> genderMap = new EnumMap(Gender.class); where Gender is public

  • 0

I have a EnumMap:

EnumMap<Gender, Integer> genderMap = new EnumMap(Gender.class);

where Gender is public enum Gender {Male, Female};

And I have req.setAttribute("genderMap", genderMap);

Now I want to get the value from genderMap by a key in JSP file:

${genderMap['Male']}

but this doesn’t get the value in genderMap. Why?

  • 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-24T09:15:59+00:00Added an answer on May 24, 2026 at 9:15 am

    Don’t use enum mappings. Just use enums as enums in Java and as strings in JSP/EL.

    I’ll assume that you need that integer because of a database mapping. E.g. Male is stored as 1 in database and Female is stored as 0 in database. In that case, you need to redesign your enum as follows:

    public enum Gender {
    
        Male(1), Female(0);
    
        private int id;
    
        private Gender(int id) { 
            this.id = id;
        }
    
        public int getId() {
            return id;
        }
    
        public static Gender valueOf(int id) {
            for (Gender gender : values()) {
                if (gender.id == id) {
                    return gender;
                }
            }
    
            return null;
        }
    
    }
    

    When populating the Person from DB by JDBC, just do

    person.setGender(Gender.valueOf(resultSet.getInt("gender")));
    

    When showing preselected options to enduser in JSP, just do

    request.setAttribute("genders", Gender.values());
    

    and

    Gender:<br/>
    <c:forEach items="${genders}" var="gender">
        <input type="radio" id="gender_${gender.id}" name="gender" value="${gender.id}" 
            ${gender == person.gender ? 'checked="checked"' : ''} />
        <label for="gender_${gender.id}">${gender}</label>
        <br />
    </c:forEach>
    

    or even without the id

    Gender:<br/>
    <c:forEach items="${genders}" var="gender">
        <input type="radio" id="gender_${gender}" name="gender" value="${gender}" 
            ${gender == person.gender ? 'checked="checked"' : ''} />
        <label for="gender_${gender}">${gender}</label>
        <br />
    </c:forEach>
    

    When collecting submitted values in servlet, just do

    Gender gender = Gender.valueOf(Integer.valueOf(request.getParameter("gender")));
    

    or when using without id in HTML

    Gender gender = Gender.valueOf(request.getParameter("gender"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that contains an Enum to do calculation. Each Enum uses
I encountered strange behavior of enum type loaded by different class loader. In common
Have I correctly added an element to a hashTable? Flows flows = new Flows(sIP,dIP);
Have you seen library for flexible working with terminal(Unix like)? I want to implement
Have following setup: MainActivity class - extends activity MyLayout class - extends View Prefs
have a table that dynamically generates text boxes in run time. I want to
Have looked for a solution for 2 days now and am beating my head
Have a look at this HTML code: <div class=overlay> <a href=#>1</a> <a href=#>1</a> <a
Have String str May 23 2011 12:20:00, want to convert it to date such
have been able to output images from BLOB, however I am now wanting to

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.