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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:32:51+00:00 2026-05-27T01:32:51+00:00

Instead of hardcoding the years in my dropdownlist, I’m going to pass over a

  • 0

Instead of hardcoding the years in my dropdownlist, I’m going to pass over a year as the first option value and then want the following 2 values to be the previous year and so on. Something like this:

<select name="workloadYear">
    <option value="2008" <c:if test="${form.workloadYear == 2008}">selected="selected"</c:if>>2008</option>
    <option value="2007" <c:if test="${form.workloadYear == 2007}">selected="selected"</c:if>>2007</option>
    <option value="2006" <c:if test="${form.workloadYear == 2006}">selected="selected"</c:if>>2006</option>
</select>

How can I do this without hardcoding the years?

  • 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-27T01:32:52+00:00Added an answer on May 27, 2026 at 1:32 am

    You can get the current year in EL as follows:

    <jsp:useBean id="now" class="java.util.Date" />
    <fmt:formatDate var="year" value="${now}" pattern="yyyy" />
    

    (it’s now available as ${year})

    You can do a loop in JSP using <c:forEach>:

    <select name="workloadYear">
        <c:forEach begin="0" end="2" varStatus="loop">
            <c:set var="currentYear" value="${year - loop.index}" />
            <option value="${currentYear}" ${form.workloadYear == currentYear ? 'selected="selected"' : ''}>${currentYear}</option>
        </c:forEach>
    </select>
    

    This will display the current year and the 2 previous years as options.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Instead of hardcoding the default @author template I would like Eclipse to use user's
How can I print the columns specified in fields_i_want instead of hardcoding the column
Instead of coloring whole text, I want to color each word in a dropdown..
This question is likely noobish. Instead of hardcoding the MySQLdb connection object: e.g, db
Instead of hardcoding text in the UI we use placeholders with keys which get
How to call controller function from template in Django instead of hardcoding URIs?
I want to read json response as name and value pairs in my JQuery
Instead of something like this: Func<bool> func; bool Property { get {return func();} }
Instead of opening several transactions (read a table, write to a table, write to
...instead of using the Atom syndication format? Atom is a well-defined , general-purpose XML

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.