Spring Framework
  1. Spring Framework
  2. SPR-7414

In http, put method can have request body but RequestParam Annotation doesn't work

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Web
    • Labels:
      None

      Description

      @RequestMapping(value="/put", method=RequestMethod.PUT)
      @ResponseBody
      public Result testPutParam(@RequestParam("name") String name)

      { Map<String, String> m = new HashMap<String, String>(); m.put("name", name); m.put("msisdn", "010-7464-5279"); return new SuccessResult<Map<String, String>>(m); }

      RequestParam annotation doesn't work.

      if I use RequestBody annotation instead, I can see request body

      I call this api as below

      HttpPut httpPut = new HttpPut("http://localhost:8080/put");
      httpPut.addHeader("Accept", "application/json");

      // Add data
      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
      nameValuePairs.add(new BasicNameValuePair("name", "louisHuh"));
      httpPut.setEntity(new UrlEncodedFormEntity(nameValuePairs));

      HttpClient client = new DefaultHttpClient();
      HttpResponse response = client.execute(httpPut);

        Activity

        Hide
        Juergen Hoeller added a comment -

        I'm afraid this is a general limitation with the Servlet API: Parameters are only defined for GET requests (with parameters taken from the query String) and POST requests (with parameters taken from the request body). In all other scenarios, HttpServletRequest's getParameter won't work. Spring's @RequestParam simply delegates to the HttpServletRequest and, as a consequence, inherits the same limitation.

        Juergen

        Show
        Juergen Hoeller added a comment - I'm afraid this is a general limitation with the Servlet API: Parameters are only defined for GET requests (with parameters taken from the query String) and POST requests (with parameters taken from the request body). In all other scenarios, HttpServletRequest's getParameter won't work. Spring's @RequestParam simply delegates to the HttpServletRequest and, as a consequence, inherits the same limitation. Juergen
        Hide
        Arjan van B. added a comment -

        Related, with workarounds: SPR-7030

        Show
        Arjan van B. added a comment - Related, with workarounds: SPR-7030

          People

          • Assignee:
            Juergen Hoeller
            Reporter:
            Louis Huh
            Last updater:
            Arjan van B.
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              1 year, 12 weeks, 2 days ago