Does Spring @RequestParam and req.getParameter("xx") work differently..?
ajax, java, spring
Solution
The default for `@RequestParam` is that the value is required, and it will throw an exception if nothing is there. On the other hand with `getParameter` it would just be passing a null down into the next method. So if there are some times that you're not supplying all three parameters, then it would not work properly with the change.
Edit:
Regarding the additional information you posted: There is some special handling inside AnnotationMethodHandlerAdapter that changes the routing when a void method takes in HttpServletResponse as a parameter. Basically it assumes that since you took in the response, you're handling any output that needs to be generated and it disables default view resolution. This would cause the server to simply reply 200 with an empty response body.
In the case where you have a void method, but weren't reading in the HttpResponse object, it was reverting to default view resolution. This probably led to an error being generated since I doubt you have a .jsp file named add_server anywhere! :) The request sill "works" since your service call is done and committed before the method returns and Spring attempts view resolution. The ajax call ends up going to the error handler instead of the success handler though.
tl;dr sometimes annotated controller "magic" is a little bit too magical :)
Problem
Please understand my English is bad. I use Spring MVC and I replaced this source ``` @RequestMapping("/ajax/add_server") public void addServer(HttpServletRequest request, HttpServletResponse response) throws Exception { String host = request.getParameter("host"); String port = request.getParameter("port"); String state = request.getParameter("state"); serverService.addServer(host, port, state); } ``` to ``` @RequestMapping("/ajax/add_server") public void addServer( @RequestParam("host") String host, @RequestParam("port") String port, @RequestParam("state") String state) throws Exception { serverService.addServer(host, port, state); } ``` addServer() Method is called by AJAX. My ajax loading image is gone in case of using req.getParameter(), but the images isn't gone when i use @RequestParam.. I guess Ajax XMLRequest Object doesn't get any success MSG. but I don't know why and is this normal? Additional Discovery!! ``` @RequestMapping("/ajax/add_server") public void addServer( @RequestParam("host") String host, @RequestParam("port") String port, @RequestParam("state") String state, HttpServletResponse response) throws Exception { serverService.addServer(host, port, state); } ``` I added response to Parameter then the image's gone. I don't know Why. I leave this for my Reference. The Controller method with void return type uses URI-BASED VIEW. For example, this following source uses ajax/add_server.jsp as view. ``` @RequestMapping("/ajax/add_server") public void addServer( @RequestParam("host") String host, @RequestParam("port") String port, @RequestParam("state") String state) throws Exception { serverService.addServer(host, port, state); } ```