Question

I have a table that stores different Questions along with options with format.I am storing all this in an arraylist within a session in servlet.Now,i am getting this session in jsp page from servlet.

I want to display one question with its option at a time and then that questions should not be printed next time.It should get incremented to the next question.

I have doubt in this ,how do i implement this logic.Whatever i have tried till now displays all questions in jsp page.

please help.

Was it helpful?

Solution

Create an instance variable in your jsp and increment it each time.

<%! int i = 0;%>

It makes i stay around after execution. Each time you run the page, the last value of i stays in memory.

for getting one particular question:

 <%

    List list = fetchyourlisthere();

    // check its size

    if(i<list.size()) {

      list.get(i);

    // this will return you the object for that particular question.

     // now increment i

     i++;
    }

    %>

so each time the page loads, you will have new question from the list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top