1

I'm sending two parameters using GET (through URL) and I would like my request method to receive them like this...

Here's the controller:

@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 this error

org.springframework.web.bind.MissingServletRequestParameterException:Required java.lang.String parameter 'lname' is not present
1
  • please format you sample code Commented Aug 22, 2010 at 12:41

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.