开发者

Usage of @RequestParam throws error in Spring 3

开发者 https://www.devze.com 2023-04-05 22:43 出处:网络
I am using the @RequestParam 开发者_Go百科annotation to get the request parameters , and using the same to insert the values into the DB.

I am using the @RequestParam 开发者_Go百科annotation to get the request parameters , and using the same to insert the values into the DB. I have setup the controller to re-direct to the same page which contains the text fields for the user to enter the values, which are being read using the @RequestParam annotation.

But after I enter the values into the text fields , and click submit , it throws this error

Request processing failed; nested exception is java.lang.IllegalArgumentException: Name for argument type [java.lang.String] not available, and parameter name information not found in class file either.

I am a newbie to Spring 3 , and unable to understand the error. Can anybody please shed light on the same.

Thanks in advance, Vivek


In order to inject the value of request parameter into your handler method parameter, either one of the following should be satisfied

  1. The name of the request parameter must match the name of the method parameter. e.g. Following will inject the request parameter named "studentName" into the method parameter studentName

    public String goToStep(@RequestParam String studentName)

  2. The request parameter name must be explicitly specified if it does not match the method parameter. The following will inject "nameOfStudent" request parameter into studentName:

    public String goToStep(@RequestParam("nameOfStudent") String studentName)

Please post your handler method code if your issue continues to persist.


I asked for the version you are using because I ran with a similar problem a few days ago. I was using Spring 3.1.0.M2 and the same exception appeared when I was using @PathVariable in proxied @Controller.

It was caused by a resolved known bug. You just have to switch to 3.0.6 or try the nightly build 3.1.0.BUILD-SNAPSHOT. Of course, the latter option is not recommended for production environment.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号