Which one better, create one servlet per use case or group it? For example User has 10 pages. Each of them has its own job such as do query, input data, show pre-calculate result etc. I think about two ways,
- Create 10 servlet for each page to process data on them so they'll be Page1Servlet.java, Page2Servlet.java etc.
- Just one servlet with all method combined in one (/servlet/user?do=???) with switch case to manage what method to use and the directive
I think you should combine two these ways. This approach describes wellknown pattern "Model2".
Roughly speaking, when you using this approach, you have one main servlet (for example ControllerServlet) and many other specific workers (for example, LoginServlet, LagoutServlet, ErrorServlet, RegistrationServlet etc...) and when ControllerServlet received request it must dispatch this request for one predefined servlet, if corresponding servlet doesn't exist ControllerServler must forward request to ErrorServlet.
If to you is interesting I have uploaded the source codes of the my very old project which hosts on google app engine and used this approach:https://github.com/cooker/moviebook
I hope, that it will help.