dimanche 7 août 2016

How to create web app using servlets that handle several clients and creating instance of user once?

I am creating web application using Servlets. The idea is that some question is presented to user, then, according to his answer next question is presented and etc. I have a class in backend Java, where I decide which question will be next etc. And my app should be able to handle several clients in the same time. Also, I have a submit button so that after every answer the page was reloaded and new question was presented. So I created the instance of a client, but when he submits his answer, page reloads and service() method in Servlet runs, so my instance is instantiated and created again(but I do not want it, because my next questions will be based on his last answers). Then I tried to make user's instance global so that I do not instantiate it in the service(), instead, I did it in init(), so it was instantiatedonly once. But because it is global now, when new clients loads the page, the user's instance is the sme for everyone, so the queestions are the same. Help me please! Thank you!!!

Aucun commentaire:

Enregistrer un commentaire