tom
tom

Reputation: 5504

How to set the value to send to servlet from list of radio button in jsp

I am trying to send the selected radio button value to servlet but its not working please see below code.

<c:set var="questionAnswers" value="${quentionAnsers[0]}" />
    <c:choose>
        <c:when test="${questionAnswers == 'single'}">
            <c:forEach var="answers" items="${quentionAnsers}" >
                <input type="radio" name="gender" value="${selectedAnser}"/>${answers}
                            </c:forEach> 
                            </c:when>
                            <c:otherwise>
                                <input type="radio" name="gender" value="Male" />Male
                                <input type="radio" name="gender" value="Female" />Female</td>
                            </c:otherwise>
                         </c:choose>

In my backed been i am doing

String selectAnser= request.getParameter(selectedAnser()); 

But i am not getting the value.

Also is there a way that i can only display from list of 2 to list of 5 as radio buttons?

Please Advice!

Upvotes: 0

Views: 659

Answers (1)

GUISSOUMA Issam
GUISSOUMA Issam

Reputation: 2582

You shoulhd be able to get the parameter with the input name:

String selectAnser= request.getParameter("gender");

In your jsp are you sure value attribute shoud be ${selectedAnser}, for me it should be the variable ${answers}:

<c:forEach var="answers" items="${quentionAnsers}" >
                <input type="radio" name="gender" value="${answers}"/>${answers}
</c:forEach> 

Upvotes: 1

Related Questions