1

Let's say this is my MainController:

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.websocket.Session;

public class MainController extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.getRequestDispatcher("/login.jsp").forward(request, response);
    }

    public void myMethod() {
         // my code
    }

}

If it is a bad practice, can you also explain why?

1 Answers1

1

Nothing stops you from doing so. It's all about the architecture you follow. In MVC, The model, view, and controller(servlets) are actually decoupled.

Tomorrow if there is a change in the business logic. Model(service to be more specific) is the only layer that would be affected and the other two components don't event care

This Decoupling helps you in writing complex applications(desktop and web both).

Coupling and cohesion is another fundamental aspect that one should care(apart from DI IOC) while writing applications.

Yati Sawhney
  • 1,372
  • 1
  • 12
  • 19