1

I am very new to WebApp in general and Spring MVC in particular. I am writing a small project where I wish to get the key value pair posted by a client. I can do it if I know the value of the key beforehand. The tutorials I've read in parameter processing also assumes that you know the parameter name. But what if I don't know the parameter name.

@Controller
@RequestMapping(value = "/keyvaluepost")
public class ProcessController {


@RequestMapping(method = RequestMethod.POST)
public String doPost(
        HttpServletRequest request,
    HttpServletResponse response,
    @RequestParam("knownKey") String knownKey) {

        // process knownKey here

        // but what if i do not know the key?

    }

Basically, I am looking for something similar to $_POST in php where I can get the key value pair. Any help will be greatly appreciated. Thanks.

user3386275
  • 65
  • 1
  • 2
  • 10
  • Did you try searching for similar questions asked earlier on SO. I found one. See if it helps: http://stackoverflow.com/questions/7312436/spring-mvc-how-to-get-all-request-params-in-a-map-in-spring-controller – Sachin Sharma Mar 24 '14 at 06:14
  • 1
    Thanks. I saw something similar but when I saw Map I thought maybe there is a simpler solution (sorry for being a noob) because I only want 1 key value pair. But it seems that the @RequestParam Map is really the simplest solution to this problem. Thanks thanks. – user3386275 Mar 24 '14 at 06:40
  • If you don't know the key, then you don't have a handle on the key-value pair. Then there is only one way. You have to go through the whole stuff to get what you want. :) – Sachin Sharma Mar 24 '14 at 06:44
  • The PHP `$_POST` is an associative array, which would be equivalent to a `Map` in Java. Therefore, if you are looking for a substitute for `$_POST`, you will have to look at using a `Map`. – manish Mar 24 '14 at 08:52

0 Answers0