Best Frameworks For Full Stack Java Developers

Best Frameworks For Full Stack Java Developers

Introduction:

In the present time to become a Full Stack Java developer, a programmer has to know about the front-end development as well ass the backend development in a complete manner. It means a full stack developer ha to know the complete idea about how to handle all the work of databases, servers, systems engineering, and clients in complete manner.

In the present scenario, it seems that the “Full Stack Development” topic has already become a new job trend. During the full stack development, we need to use the framework also to design the both the front end and backend of application. 

  1. The most popular framework is Spring MVC where the programmer are used to design the complete application. In the application they are used to process the HTTP request by means of request and response process. 
  2. One of the frequently asked Spring MVC Interview questions is about explaining the flow of web request.
  3. i.e. how an HTTP request is processed from start to end. In other words, explaining the flow of request in Spring MVC. 
  4. It all starts with the client, which sends a request to a specific URL. 
  5. When that request hits the web container like Tomcat it looks into web.xml and finds the Servlet or Filter which is mapped to that particular URL. 
  6. It the delegate that Servlet or Filter to process the request. Since Spring MVC is built on top of Servlet, this is also the initial flow of request in any Spring MVC based Java web application.

Here the Web container like Tomcat is responsible for creating Servlet and Filter instances and invoking their various life-cycle methods like init(), service(), destroy(). In the case of an HTTP request, HttpServlet handles that, and depending upon the HTTP request method various doXXX() method is invoked by container like doGet() to process GET request and doPost() to process POST request.

Working procedure of MVC:

  1. The Spring MVC, we need to declare the DispatcherServlet from Spring MVC jar into web.xml. 
  2. This Servlet listens for a URL pattern * as shown in below web.xml, which means all request is mapped to DispatcherServlet.
  3. Though it is not mandatory, you can have other servlet mapped to other URL if you want to, but if you are using Spring MVC to develop a web application or RESTful web service, it makes sense to pass through all request via DispatcherServlet.

How Spring MVC process an HTTP Request

Here is the web.xml configuration for Spring MVC, you can see that DispatcherServlet is mapped to all request using URL pattern *

<web-app>


<!-- The front controller of this Spring Web application, responsible 

for handling all application requests -->

<servlet>

<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/config/web-application-config.xml</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>


<servlet-mapping>

<servlet-name>example</servlet-name>

<url-pattern>*</url-pattern>

</servlet-mapping>


</web-app>

The URL pattern is important, if the request matches the URL pattern of DispatcherServlet then it will be processed by Spring MVC otherwise not. The DispatcherServlet passes the request to a specific controller depending on the URL requested. How does DispatcherServlet know which request needs to be passed to which controller?

Mapping of Controller:

The below class is a Controller that will process any request having URI "/appointments". It also has @GetMapping, which means that the method will be invoked when a GET request is received for this URL. The method annotated with @PostMapping will be invoked if the client sends a POST request to the "/appointments" URI.

@Controller

@RequestMapping("/appointments")

public class AppointmentsController {

@GetMapping

public Map get() {

return appointmentBook.getAppointmentsForToday();

}


@PostMapping

public String add(@Valid AppointmentForm appointment, BindingResult result) {

if (result.hasErrors()) {

return "appointments/new";

}

appointmentBook.addAppointment(appointment);

return "redirect:/appointments";

}

}

After processing the request, the Controller returns a logical view name and model to DispatcherServlet and it consults view resolvers until an actual View is determined to render the output. DispatcherServlet then contacts the chosen view e.g. Freemarker or JSP with model data and it renders the output depending on the model data.

This Rendered output is returned to the client as an HTTP response. On it's way back it can pass to any configured Filter as well like Spring Security filter chain or Filters configured to convert the response to JSON or XML.

The DispatcherServlet from Spring MVC framework is an implementation of Front Controller Pattern (see Patterns of Enterprise Application Architecture) and it's also a single point of entry - handle all incoming requests, but again that depends upon your URL pattern mapping and your application.

It delegates requests for further processing to additional components like Controllers, Views, View Resolvers, handler mappers, exception handlers, etc. It can also map directly to /, but then the exception for handling static resources needs to be configured. If you look at the web.xml configuration it also pre-loaded using the load-on-startup tag.

Spring MVC work Flow

here is the flow of an HTTP request in Java application created using the Spring MVC framework:

  1. The client sends an HTTP request to a specific URL
  2. DispatcherServlet of Spring MVC receives the request
  3. It passes the request to a specific controller depending on the URL requested using @Controller and @RequestMapping annotations.
  4. Spring MVC Controller then returns a logical view name and model to DispatcherServlet.
  5. DispatcherServlet consults view resolvers until actual View is determined to render the output
  6. DispatcherServlet contacts the chosen view (like Thymeleaf, Freemarker, JSP) with model data and it renders the output depending on the model data
  7. The rendered output is returned to the client as a response

The following diagram explains the workflow of Spring MVC framework:


Scope @ N9 IT Solutions:

  1. N9 IT Solutions is a leading IT development and consulting firm providing a broad array of customized solutions to clients throughout the United States. 
  2. It got established primarily with an aim to provide consulting and IT services in today’s dynamic environment.
  3. N9 IT also offers consulting services in many emerging areas like Java/J2ee, Cloud Computing, Database Solutions, DevOps, ERP, Mobility, Big Data, Application Development, Infrastructure Managed Services, Quality Assurance and Testing.



OUR BLOG

What Is Happening