In Section 15.3.2.3 Supported handler method arguments and return types of the Spring 3.0 documentation, it says that a java.io.OutputStream or java.io.Writer can be specified as a parameter of a method annotated with @RequestMapping "for generating the response's content. This value is the raw OutputStream/Writer as exposed by the Servlet API." Is it the method's responsibility to close the writer before it finishes or should it remain open and some other Spring process will close it?
Method parameters annotated with @RequestParam are required by default. will correctly invoke the method. When the parameter isn't specified, the method parameter is bound to null.
The following are the supported method arguments: Request or response objects (Servlet API). Choose any specific request or response type, for example ServletRequest or HttpServletRequest . Session object (Servlet API): of type HttpSession .
@RequestParam makes Spring to map request parameters from the GET/POST request to your method argument. @RequestBody makes Spring to map entire request to a model class and from there you can retrieve or set values from its getter and setter methods.
The DispatcherServlet The Controller takes the request and calls the appropriate service methods based on used GET or POST method. The service method will set model data based on defined business logic and returns view name to the DispatcherServlet.
It should leave it alone. As a general rule of thumb, if your code didn't open it, then it shouldn't close it, either.
In this case, the servlet container (not Spring) is responsible for flushing and closing all streams.
You could do it yourself, I doubt it would do any harm, but there's no need to do so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With