views:

161

answers:

2

Hi, i'm sending two parameters using GET (through URL) and woul like my request method to receive them like this ...

@RequestMapping("/basketItems")
public String basketItems(
    @RequestParam("fname") String firstName, 
    @RequestParam("lname") String lastName, 
    Model model) {

    Customer customer = customerManager.getCustomer(firstName, lastName);
    Basket basket = basketManager.getBasket(customer.getReferenceNumber());

    model.addAttribute("basket", basket);
    model.addAttribute("totalItems", basketManager.getTotalNumberOfItems(basket));
    model.addAttribute("totalPrice", basketManager.getTotalProductPrice(basket));

    return "basketItems"; 
}

I get an error that org.springframework.web.bind.MissingServletRequestParameterException: Required java.lang.String parameter 'lname' is not present

A: 

What is your request URI?

MissingServletRequestParameterException is thrown because there is no request parameter of type String with name lname to bind to variable lastName

arjan
+3  A: 

Your HTTP request doesn't have the parameter lname present. Either include that parameter in the request, or put required = "false" on the annotation for lname:

@RequestParam(value="lname", required="false")

If you put required = "false", then the variable assigned to lname will be null in that method, so be aware of that in your code.

For some more information, look at the relevant part of the Spring MVC documentation.

Noel M
Thanks, i had my request parameters appended incorrectly...
sonx