I started to develop web applications not so long ago, and therefore there are a lot of unknown things in this field for me. My question concerns web development using the Java language. Assume that we need to develop a client-server application, where the client is a browser. As far as I know, there are at least two ways to communicate.
An HTTP server work on the server side and a container for a Java application (back-end). The HTTP server redirects requests to another port, which is binded with the Java application. The Java application sends to the client pages with dynamic content from a database, for example, as a response to a concrete client's request. The application uses a template enginge for this. Timeleaf or Velocity, for example.
An HTTP server sends only static files (HTML pages, CSS and Javascript files), and further a client starts to send asynchronious requests to the server using Javascript code. Requests are sent via HTTP/HTTPS in the JSON format (or XML). This approach uses REST principles. A server application written in Java takes these requests from a certain port, processes them and sends responses in the same manner. A page refreshes dynamically on the client side, without reloading.
Though I wrote about Java, these approaches are used with other programming languages, Python, for instance.
I was told that the first apprach is considered as bad in the Java community. But I haven't heard concrete arguments. I would like to know them.
Many thanks for your time and answers.