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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:54:31+00:00 2026-06-03T07:54:31+00:00

I have a form with sequentially named fields (field1, field2, etc) that I need

  • 0

I have a form with sequentially named fields (field1, field2, etc) that I need to output in the same order for computation purposes. JSTL doesn’t seem to sort in alphabetic order by default. Is there a way to do so?

Here is the code:

<c:if test="${param.submitted}">

        <c:set var="hits" value="1" />
        <c:set var="damage" value="0" />

        <table border="1">
            <tr>
                <th>Attack</th>
                <th>Damage (Orig)</th>
                <th>Damage (Scaled)</th>
                <th>Total</th>
            </tr>

        <!-- Loop through form fields -->
        <c:forEach var="information" items="${paramValues}" varStatus="field">
            <!-- Loop through fields' values -->
            <tr>

            <c:forEach var="currentField" items="${information.value}">
                <c:if test="${!empty currentField}">
                    <c:if test="${fn:contains(currentField, '|')}">
                        <c:set var="currentAttack" value="${fn:substringAfter(currentField, '|')}" />
                        <td><c:out value="${hits}" />: <c:out value="${fn:substringBefore(currentField, '|')}" /></td>
                        <td><c:out value="${fn:substringAfter(currentField, '|')}" /></td>

                        <td>
                        <c:choose>
                            <c:when test="${hits < 3}">
                                <c:out value="${currentAttack}" />
                                <c:set var="damage" value="${damage + currentAttack}" />
                            </c:when>
                            <c:when test="${hits == 3}">
                                <c:out value="${currentAttack * 0.8}" />
                                <c:set var="damage" value="${damage + (currentAttack * 0.8)}" />
                            </c:when>
                            <c:when test="${hits == 4}">
                                <c:out value="${currentAttack * 0.7}" />
                                <c:set var="damage" value="${damage + (currentAttack * 0.7)}" />
                            </c:when>
                            <c:when test="${hits == 5}">
                                <c:out value="${currentAttack * 0.6}" />
                                <c:set var="damage" value="${damage + (currentAttack * 0.6)}" />
                            </c:when>
                            <c:when test="${hits == 6}">
                                <c:out value="${currentAttack * 0.5}" />
                                <c:set var="damage" value="${damage + (currentAttack * 0.5)}" />
                            </c:when>
                            <c:when test="${hits == 7}">
                                <c:out value="${currentAttack * 0.4}" />
                                <c:set var="damage" value="${damage + (currentAttack * 0.4)}" />
                            </c:when>
                            <c:when test="${hits == 8}">
                                <c:out value="${currentAttack * 0.3}" />
                                <c:set var="damage" value="${damage + (currentAttack * 0.3)}" />
                            </c:when>
                            <c:when test="${hits == 9}">
                                <c:out value="${currentAttack * 0.2}" />
                                <c:set var="damage" value="${damage + (currentAttack * 0.2)}" />
                            </c:when>
                            <c:otherwise>
                                <c:out value="${currentAttack * 0.1}" />
                                <c:set var="damage" value="${damage + (currentAttack * 0.1)}" />
                            </c:otherwise>
                        </c:choose>
                        </td>
                        <td><c:out value="${damage}" /></td>

                        <c:set var="hits" value="${hits + 1}" />
                    </c:if>
                </c:if>
            </c:forEach>
            </tr>
        </c:forEach>

        </table>
    </c:if>

    <form action="foo.jsp" method="post">
        <input type="hidden" name="submitted" value="true" />
        <c:forEach var="rows" begin="1" end="5" varStatus="stat">
            <p> ${stat.count}:
                <select name="move${stat.count}">
                    <option value="">-Select-</option>
                    <c:forEach var="row" items="${result.rows}">
                    <option value="${row.attack}|${row.damage}">${row.attack}</option>
                    </c:forEach>
                </select></p>

        </c:forEach>
        <input type="submit" name="submit" value="Go" />
    </form>
  • 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-06-03T07:54:33+00:00Added an answer on June 3, 2026 at 7:54 am

    JSTL doesn’t change the sort order or something and has also no facilities at all to sort collections. It just allows you to control the flow of HTML generation in JSP and thus displays whatever you told it to display.

    Your problem is caused elsewhere. Most likely you’re using a HashMap instead of LinkedHashMap to hold the fields. A HashMap is by nature unordered while a LinkedHashMap is ordered by insertion order exactly like as a List.


    Update you’re iterating over the implicit EL variable ${paramValues} which refers the ServletRequest#getParameterMap() which indeed returns an unordered HashMap. If you need to retain the order of the request parameters, you’d have to solve the problem differently. For example, by using fixed and indexed parameter names so that you can refer them directly, or by just using a MVC framework.

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

Sidebar

Related Questions

I have a checkbox group in one form that I need to be posted.
I have form, where some fields are looks like rows, so I can add/delete
I have 10 form fields and I want to append a number next to
I have a form that performs calculations live as the user enters data. However,
I have form that displays several keywords (standard set of choice lists that changes
I have form fields where the user enters in: percents: 50.5% money: $144.99 dates:
I'm going to have html form that is going to send out chunks of
I have a form on an HTML page with multiple submit buttons that perform
I need a select from table which does not have column that tells when
I have a form which has over 100 fields (most of which are checkboxes)

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.