You can call a servlet to get the next question when you click next.
The response will have the new question and will reload the same page.
Submit button can call another servlet to save answer to DB and response can load same page with same/next question.
"One of the best things you could do is to simplify a larger application into a smaller one by reducing its process and complexity - Fowler"
Joined: Jun 22, 2012
what i have done till now is very simple.
i have created a servlet to fetch questions from the database.
and then i have stored the fetched records from the database to arraylist and then i am calling the arraylist in the jsp page.
code for jsp page.
to save the user response i am reloading the same servlet again and again to insert records in the database, my servlet for fetching records have also the code for saving the user's response. this is all what i have done till now, this is also working fine, but there are few issues.
1. i am not able to implement previous button.
2. if suppose my database has 20 questions, then for 19 questions it is saving the user's response and for the last question it is not saving the user's response in the database and giving error.
3.this is also not a good approach as my jsp has a lot of scriptlets, i want to remove this.
i have provided with you all the things which i have done till now now please help me in solving this issue.
int current = 0;
int previous = 0;
List qlist1= (ArrayList)qlist;
if (request.getParameter("hidden") != null)
current = Integer.parseInt(request.getParameter("hidden"));
I'm obliged to point out several critical problems with your design. First, that's way too much code in the servlet. It should contain maybe 10 lines of code at the most. All that database code belongs in a Data Access Object that returns the data in a collection. Second, get rid of all that Java code in the JSP. There should be no code in a JSP, they are for generating the view only. All processing should take place in Java classes before the data is sent to the JSP. That scriptlet technique that you're using is 13 years old. Throw it away.
"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
Just to echo that good advice, you will find it a LOT easier to debug your application if all requests go to a servlet instead of a JSP page. If this was my problem I would have provision in that servlet for logging exactly what each request contains.
I am showing a timer on the question page , the timer works fine.
But the problem is if user refreshes the page , the timer starts from the beginning.
I don`t want that , Even if user refresh the page it should start from previous time.
So what I am thinking is , when user refreshes the page I will send the time parameters( minute & seconds) to servlet .
And in the jsp page I will start the timer from the same param returned by servlet .