1

I am creating an online test application using struts framework. In the jsp page i am using display tag to navigate through the questions. i can able to display one question with 4 options per page. here is my code.

<form method="get">
 <display:table name="${sessionScope.questionList}" id="quest" pagesize="1"                                                                                                                          
     requestURI="display.jsp">
        <display:column title="Stuff">
            <c:out value="${quest.quesId}"/><br/>
            <c:out value=" ${quest.question}"/><br/>   
    <input type="checkbox" name="ans1" value="${quest.option1}" />  <c:out value="${quest.option1}"/><br/>
    <input type="checkbox" name="ans2" value="${quest.option2}" />  <c:out value="${quest.option2}"/><br/>
    <input type="checkbox" name="ans3" value="${quest.option3}" />  <c:out value="${quest.option3}"/><br/>
    <input type="checkbox" name="ans4" value="${quest.option4}" />  <c:out value="${quest.option4}"/><br/>
        </display:column>
    </display:table>
</form>

My problem is, in page 1 if a user selects one checkbox option and go to to the next page, that checkbox is unticked when he comes back to that page and viceversa. how can i solve this problem ? please help me regarding this.

Thanks in advance

1 Answers1

0

HTTP is stateless so all values are lost when you navigate to the next page. You can pass the values in the url as parameters. You need to create variables with names matching the name property of your checkboxes on the backing bean. You also need to create getters and setters so that the framework (if you use one) can map the values to those variables

Then you can access these variables from your page and use JSTL to check if a condition is met and tick the checkboxes like so

<c:if test="${condition}">checked="checked"</c:if>
steven35
  • 3,747
  • 3
  • 34
  • 48