What I've been trying to do is to display radio buttons with a corresponding value inside a foreach loop. Then, I'd like to retrieve the value of the selected radio button on the next JSP page.
Here is part of my coding.
<form action="EventList_to_seats_servlet" method="POST">
//There are irrelevant lines here.
<c:otherwise>
<c:forEach var="ID" items="${EventID}">
//EventID, a list of Integer, comes from the previous servlet,
//set in HttpServletRequest
//i.e. I wrote "request.setAttribute("EventID", EventID);" in the previous step.
<li>
<%= "Event ID: "%> ${ID}
<input type="radio" name="${EventID}" value="ID" /><br><br>
</li>
</c:forEach>
<input type="submit" value="Submit" name="submitOrderID" />
</c:otherwise>
</form>
I'd like to retrieve the selected radio button's name and value on the next servlet.
Here is part of the next step (a servlet, called "EventList_to_seats_servlet").
BookingInfo bi = new BookingInfo();
//It's a bean dedicated to storing information entered by the client.
bi.setEventID(request.getParameter("ID"));
//It doesn't seem to be the right way to retrieve the selected radio button's name/value
I've tested multiple ways to get the value from the JSP to the servlet, but I still can't find out how to do this, particularly because both the radio button's name and value are generated dynamically.
I'd appreciate if you would give any advice.
P.S.
I've found a similar posting here, but I honestly couldn't fully understand it, mainly because I'm not really sure how to use ${ }
.
${ }
seems to be used to access values set by HttpServletRequest (i.e. request.setAttribute("xxx", yyy);
).
However, after I referred to this posting , I thought ${ }
seemed to be used for getting values from a Bean too.
In the above example, do you think that getting the yyy
using ${xxx}
is a common to use ${ }
?