Question

Annotation with spring params is not working.

@RequestMapping(value = "/login", method = RequestMethod.PUT)
public @ResponseBody ResponseMsg login(@RequestParam String userName, @RequestParam String password ) 
{
    ResponseMsg responseMsg = CommonUtils.checkParam(userName, password);

    if(responseMsg.getStatus().equalsIgnoreCase("True"))
    {
        responseMsg =  userService.login(userName, password);
    }
    return responseMsg;
}

I'm using this function for get value in put but it shows 400 Bad Request. Any help?

Was it helpful?

Solution

right ans is this ... and thx to OQJF

@RequestMapping(value = "/login", method = RequestMethod.GET)
    public @ResponseBody ResponseMsg login(@RequestHeader(value="username", required=false) String userName, 
            @RequestHeader(value="password", required=false) String password ) {

        ResponseMsg responseMsg = CommonUtils.checkParam(userName, password);
        if(responseMsg.getStatus().equalsIgnoreCase("True"))
            responseMsg =  userService.login(userName, password);
        return responseMsg;
    }

OTHER TIPS

First use firebug to see what parameters that you send to controller. If the parameter names is correct. I think the reason is that the field annotated with @RequestParam that the default is required, it means that the parameters that sent from client must contains them which are userName and passWord, change to this :@RequestParam(value="username" required=false) String userName, @RequestParam(value="password" required=false) String password and try it.

I'm not sure you want to use a post in this scenario. But you could try accessing the header params as follows:

@RequestMapping(value = "/login", method = RequestMethod.PUT)
public @ResponseBody ResponseMsg login(@RequestHeader("username") String userName, @RequestHeader("password") String password ) {
                ResponseMsg responseMsg = CommonUtils.checkParam(userName, password);
                if(responseMsg.getStatus().equalsIgnoreCase("True"))
                    responseMsg =  userService.login(userName, password);
                return responseMsg;
            }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top