AJAX MVC Application Architecture

I wrote the bare bones of my application using the MVC pattern. I currently do not have any AJAX features in my application, but I was looking for suggestions on how to change the architecture of my application to achieve this, for this purpose I will try my best to describe my current architecture:

  • I have a controller servlet "controller.java" that reads the servlet path, ie request.getServletPath() to determine the required action
  • I have several different corporate Java Beans (EJB 3.1) that handle business logic and that are called by my servlet controller depending on the requested action.
  • I have several views that relate to various aspects of my application to which the request is forwarded (by the servlet controller) based on the requested action (i.e. request.getRequestDispatcher(url).forward(request, response); )

I understand that the existing architecture can support AJAX functionality (by matching the template with my "controller.java" servlet), but I get to the point that I have a huge amount of actions supported by my controller, and this getting confusing.

Does anyone have any suggestions? Is there a standard template for this? I am trying to stay free from any frameworks just now, as I am a relative newbie !:-)

thanks

+4
source share
3 answers

If your controller supports a huge number of actions - where you need refactoring. In general, your architecture looks correct if the number of actions is reasonable (up to 10, I would say) for each controller.

One of the possible ways of refactoring is combining controllers into modules .

+3
source

You can check ajax requests like this:

 boolean ajax = "XMLHttpRequest".equals(request.getHeader("X-Requested-With")); 

and then process the response accordingly. That is, returning the identifier of the view that should be used in redirection or redirection, or returning some JSON, which should then be written to the response body, or returning a special View object that contains this information. Given this basic MVC example , you should not expand it so much with ajax support.

0
source

Same idea with BalusC.

We have an MVC application that runs on its own. Now, to add AJAX functionality, we added jQuery and used jqGrid at presentation level. He contacts the backend through AJAX. If we remove jQuery and jqGrid, we still have a fully running MVC application.

I put the demo at http://krams915.blogspot.com/2010/12/jqgrid-and-spring-3-mvc-integration . Here we integrated Spring MVC 3 and jqGrid / JQuery

0
source

Source: https://habr.com/ru/post/1333799/


All Articles