Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In http, put method can have request body but RequestParam Annotation doesn't work [SPR-7414] #12072

Closed
spring-issuemaster opened this Issue Aug 2, 2010 · 2 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented Aug 2, 2010

Louis Huh opened SPR-7414 and commented

@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);

Reference URL: http://forum.springsource.org/showthread.php?t=93045

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Aug 30, 2010

Juergen Hoeller commented

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

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Jan 28, 2013

Arjan van B. commented

Related, with workarounds: #11692

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.