MVC – controller-to-controller in java EE

In school, say a payroll application, my professor does the following logic flow:

  • The default page would be an index.jsp page.
  • When the add button is clicked, the addform.jsp page would be called and there the user can enter the data for the payroll
  • When the submit button is clicked, the addform.jsp page will call a servlet that processes the form and add it to the table.
  • Say the insert statement works perfectly and there is no problem with the input data, the servlet will call an add.jsp page. This contains that input data the user entered before, informing the user that the data is successfully inserted into the table, and a “list of payroll” link.
  • When the “list of payroll” link is clicked, another servlet is called, this one processing all rows in the table for viewing.
  • Finally, a resultset containing all data from the table, would be bound to the request object, then the servlet will call the list.jsp to view all data in the table.

He said this is how MVC should be done.

However, I don’t like it when after the data is inserted, another jsp page have to be created just to display the input data and to inform the user that the data is successfully inserted. Why not just go directly to list.jsp page and an error.jsp page if the insert is not successful? So I thought of the following to do what I wanted:

  • Say the insert statement works perfectly and there is no problem with the input data, the servlet will call another servlet that processes all data in the table.
  • Finally, a resultset containing all data from the table, would be bound to the request object, then the servlet will call the list.jsp to view all data in the table.

But I am not sure if this is still MVC when I would call another controller when I should be redirecting to a view. Is my approach better in terms of being MVC and user friendly or my professor’s way is better?


Source: jsp

Leave a Reply