Question

What is actually sent within a http request response ?

In below simple spring controller a String is sent to client. But this string is wrapped in some html elements that the browser understands ? Is this response always the same but different frameworks just provide different convenient methods/annotations to make the process simpler ?

  @RequestMapping(value="myrequest", method = RequestMethod.GET)
  public String redirect(@RequestParam String param) {      

      return "test";

  }
Was it helpful?

Solution

In Spring MVC Framework, the lifecycle of an HTTP Request is something like this:

  1. The user makes a request of a resource, and Spring' DispatcherServlet delegates that request to an specific controller method (like redirect). This is made through a Handler Mapping that can use -for example- the annotations (like @RequestMapping) in the controllers to select an appropriate one.

  2. Tipically, Controller methods return instances of ModelAndViews, that are the classes responsible of generating some Markup (HTML, JSON, XLS a.k.a the View) and show some information in that Views (The Model). It is possible also that Controllers return Views Logical Names (like test)that should be later resolver in ModelAndView instances by a View Resolver.

  3. The View Resolver selects and appropriate view based on the Logical Name returned by the Controller, and then the View generates the Markup that is sent to the browser. For example, JstlView generates HTML Markup and AbstractExcelView generates XLS files.

So to answer your question, you must find what View Resolver is configured in your application context and find what markup is produced.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top