1

I followed may links and found I need to use @Requestbody annotation and I need to set Content-Type=application/x-www-form-urlencoded in header under @RequestMapping annotation. But I did not find any example like how can I set these body parameters in browser and get in controller

@RequestMapping(value = "/login", headers="application/x-www-form-urlencoded" , method = RequestMethod.GET)
public void login(HttpServletRequest request,
        HttpServletResponse response)
        throws IOException, ServiceException {
    // I need username and password body parameters value in controller
    }
Pramod Karandikar
  • 5,289
  • 7
  • 43
  • 68
Ari
  • 341
  • 2
  • 14
  • You can make an [`ajax`](http://api.jquery.com/jquery.ajax/) call and test your url. – Naman Gala Jun 01 '15 at 11:33
  • And default `Content-Type` is `application/x-www-form-urlencoded; charset=UTF-8` when calling the service using ajax. – Naman Gala Jun 01 '15 at 11:42
  • For `@Requestbody`, you can refer this [`SO question`](http://stackoverflow.com/questions/11291933/requestbody-and-reponsebody-spring) – Naman Gala Jun 01 '15 at 11:45
  • thanks Naman for quick response. Can you please clear the if I used body parameters types as josn then I must to return response in json as well or it can be xml or types in SPRING? – Ari Jun 01 '15 at 12:02
  • Yes, if you want the json response, then you should return json, why would you return xml? – Naman Gala Jun 01 '15 at 12:06
  • I am returning the joson response. I just want to confirm if I pass body params in json then response must be return in json? – Ari Jun 01 '15 at 12:13
  • 1
    For that you need to use @ResponseBody. Refer this http://www.beingjavaguys.com/2014/05/json-response-with-responsebody_31.html – Naman Gala Jun 01 '15 at 12:17

1 Answers1

1

You would need something like Postman client in the browser.

You can install it from here. After installation, you can refer to answer to this question to know how to use it.

Community
  • 1
  • 1
Pramod Karandikar
  • 5,289
  • 7
  • 43
  • 68
  • Thanks Promod, I got the idea about setting body parameters in browser. Do you have any idea about if I used body parameters types as josn then I must to return response in json as well or it can be xml or types in SPRING? – Ari Jun 01 '15 at 11:59