0

This is part of a research project. I have a list that is iterated in the jsp page. I'm not able to get the value of the item in the list the user selects as it picks the first in the list when I retrieve it in the servlet. Any pointers or solution would be helpful.

I tried using [status.index] to the name tag but there too I have no idea which index the user picked to get in the servlet.

<c:forEach items="${TSName}" var="TSName" varStatus="status">
<b>Resource Name:</b> ${TSName}<br>
<b>Summary:</b> ${Summary[status.index]}<br>
<b>URL: ${URL[status.index]}</b><br>
<b>Average Rating:</b> ${AvgRating[status.index]}<br>
<input type="hidden" value="${TSName}" name="tool" />
<input type="hidden" value=" ${URL[status.index]}" name="url" />
<input type="hidden" name="uuid" value="${requestScope.uuid}" />
<input type="submit" value="Proceed" /><br><br>
</c:forEach>

I would only want the exact item the user picks from the list instead of the first item of each. I'm sorry if I made it too confusing. If anything is unclear I can clarify.

@BalusC I'm sorry but you didn't answer anywhere close to my question. I had mentioned it a part of a research project and you just presumed the list of items were generated was based on a id. There were multiple conditions to get that list of items for the users. @Paul provided the most simplest and accurate answer to my question so if you could reopen the question I could mark his answer as the solution.

Rosemary
  • 71
  • 10
  • Are you talking about `` for your list? – Paul Jul 11 '19 at 15:25
  • @Paul Sorry there was a formatting issue. It's using forEach. – Rosemary Jul 11 '19 at 15:28
  • Can't you use an attribute of TSName instead of using the index? And do in your loop, for example `

    This item is selected!

    ` ?
    – Paul Jul 11 '19 at 15:32
  • @Paul Thanks. I don't mind using it. But how do I get the exact selected items in the servlet from the jsp? There is further processing required with the selected items. – Rosemary Jul 11 '19 at 15:40
  • Did you put your `
    ` tags outside your forEach loop? If so, it means all inputs generated in your loop with the same name="" have the same form and parameters will be overriden.
    – Paul Jul 11 '19 at 15:41
  • Yes, I see what you mean. Is there a work around? – Rosemary Jul 11 '19 at 15:43
  • 1
    Either use buttons, for example `
    ...
    ` or put your forms tags inside your forEach loop, at the beginning and at the end `
    ...
    `. Note that when you use buttons the form action and method are passed by the button, not the form tag.
    – Paul Jul 11 '19 at 15:47
  • @Paul Thank you! It worked brilliantly. If you add you last comment as answer. I'll mark it as answer. – Rosemary Jul 11 '19 at 17:01
  • I can't since the question has been marked as duplicate. I suggest you to read the answer [here](https://stackoverflow.com/questions/3078701/how-do-i-pass-current-item-to-java-method-by-clicking-a-hyperlink-or-button-in-j) from BalusC as he has already handled this point. – Paul Jul 12 '19 at 05:55
  • I simply wasted my time reading that answer by him which has nothing to do with my question. I had updated my question stating that. – Rosemary Jul 12 '19 at 06:03

0 Answers0