Bharat
Bharat

Reputation: 417

fetch URL parameter using spring mvc

I want to fetch url parameter in my class. my application based on Spring MVC.

While calling url: http://localhost:8080/mywebapp/dir/register.do?id=26 it gives error 400

@RequestMapping(value = "/register")
public ModelAndView finalPage(@PathVariable("id") Long id) throws NumberFormatException, Exception {
   // code...
}

Anybody can solve my problem.

Upvotes: 0

Views: 149

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279890

You say

I want to fetch url parameter in my class

but you are using @PathVariable which

indicates that a method parameter should be bound to a URI template variable

You don't have a uri template variable called id in your mapping.

What you really need is a @RequestParam. The documentation explains how to use it.

Upvotes: 2

Related Questions