Answer the question
In order to leave comments, you need to log in
Rate the bike
I would like to know the opinion of the pros about the disadvantages of such a decision.
The task that was set was to strictly separate the layout from the Java code. The use of classic java frameworks like jsp and jsf is excluded. It is understood that the layout is rich in JavaScript and depends very much on it. Lots of jQuery plugins and all sorts of Ajax stuff with asynchronous loading.
It was possible, of course, to apply a bunch of something like Angular + RESTful, but it was necessary to store the state, that is, the session. Therefore, it was decided to write on servlets.
The thought is the following. There is a global Controller servlet - by itself it is not used anywhere. It only defines methods for receiving post and get requests and returning results. It has a bunch of children, which are actually assigned to the necessary urls with annotations.
For example, they call the url /app/users/profile/1 The url /app/users is mapped with the Users controller, which has the prfile method. The parent controller checks for the presence of this method in Users and calls it, passing user id = 1 as a parameter. In Users, all the logic for processing a particular page. It receives its template, no matter where (DB, file, etc.), in the simplest case, it is html with "chunks" that it replaces with real data (it is possible to use any existing template author) and sends it back to the browser through the parent method.
There is also, for example, a Save controller mapped to /app/save and which has a bunch of methods for processing data from all forms. The parent Controller, depending on the url, calls the desired method.
For ajax calls, its child controller, which gives the data in json format, for example.
That is, something that looks like a REST implementation + a little from MVC. I briefly described the basics - the main thing is that we have a parent servlet that pulls the methods of children mapped to specific urls.
I would like to discuss the feasibility of this approach, its pros and cons. A bicycle is a bicycle, it works, but ... this is what I want to hear. In what cases such decision "will lay down" for example, or what reefs are.
Initially, the idea was taken from here habrahabr.ru/post/120715 but please note that I still do not have rest, but the return of html templates
Answer the question
In order to leave comments, you need to log in
It was possible, of course, to apply a bunch of something like Angular + RESTful, but it was necessary to store the state, that is, the session. Therefore, it was decided to write on servlets.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question