Home > Mobile >  How do I address this mapping problem for Spring MVC?
How do I address this mapping problem for Spring MVC?

Time:07-14

package com.coding;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/customer")
public class CustomerController {
    
    @RequestMapping(value="/showForm")
    public String showForm(Model theModel) {
        theModel.addAttribute("customer",new Customer());
        return "customer-form";
        
        
    }
    
    @RequestMapping("/processForm")
    public String processForm
    (@Valid @ModelAttribute("customer") Customer theCustomer,BindingResult theBindingResult) {
        if(theBindingResult.hasErrors()) {
            return"customer-form";
        }else {
        return "customer-confirmation";
    }

}
} 

New to Spring!:) I am trying to build a dynamic project using Spring MVC which is "form validation" . I tried everything possible to solve this problem "WARNING: No mapping for GET /spring-mvc-demo/customer/showForm" but its not working . Any solution please?

CodePudding user response:

As you can see this warning clearly tells the path does not exist and that it's not able to recognize at this path any handlers are available.

What you can do is, Make sure the path matches your controller method mappings.

CodePudding user response:

Have you checked localhost:8080/customer/showForm? Try this URL it will work?

CodePudding user response:

Hii Anjita I tried to reConstruct your problem it is working fine for me I have created a CustomerController class like this.

customer class

I created a login form like this loginform

And I made a request from a browse with the URL "http://localhost:8080/customer/showForm". And the output is

urlOutput

Whenever I tried to give a URL "localhost:8080/spring-mvc-demo/customer/showForm" it is showing a Whitelabel error try removing your project name in URL and try once.

  • Related