It is possible to use the same Servlet for multiple actions.
A simple way is to put an attribute name
on each button and then check in Servlet, in the parameters of request, which button was pressed. There will be an attribute with the same name
push-button.
The biggest problem of this approach is to end up with a spaghetti code, that is, several ifs
treating different things in the same method. In short, look at the organization of the code, rather than the concern of having more classes and methods.
If it’s not a trivial project, consider a framework like Spring MVC to make your work easier.
and how do I check the request parameters??
– Pacíficão
String str = request.getParameter("foo");
- just make the comparison with the string.– Renan Gomes