Spring Controller POST,GET?

0

Cześć, wytłumaczy mi ktoś dlaczego tak to działa?
Controller ma adnotacje @Controller tylko.

Oto kod który mi działa:

    @RequestMapping(value = "/",method = RequestMethod.GET)
    public String getHome(){
        return "home.html";
    }
    @RequestMapping(value = "/",method = RequestMethod.POST)
    public ModelAndView log(@RequestParam("login")String login,@RequestParam("password")String password){
        ModelAndView modelAndView =new ModelAndView();
        if(serviceManager.authentication(new User(login,password))) modelAndView.setViewName("xd.jsp");
        else  modelAndView.setViewName("auth.jsp");
        return modelAndView;
    }

W tym przykładzie metoda get działa ale post nie chce zwracać html. Zwraca mi, że post jest nieobsługiwany.

    @RequestMapping(value = "/",method = RequestMethod.GET)
    public String getHome(){
        return "home.html";
    }
    @RequestMapping(value = "/",method = RequestMethod.POST)
    public String log(@RequestParam("login")String login,@RequestParam("password")String password){
        if(serviceManager.authentication(new User(login,password))) return "cos.html";
        else  return "error.html":
    }


Tutaj html:

    <form action="/" method="post">
        <input type="text" name="login" >
        <input type="text" name="password">
        <input type="submit">
    </form>

Tutaj WebConfig:

    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("*.html").addResourceLocations("/static/");
    }
0

A jak zrobisz sobie w ten sposób:

    @GetMapping("/")
...
   @PostMapping("/")

to też nie działa?

0

Jest to aplikacja Spring/Spring Boot?

Jakiś link do repo?

1 użytkowników online, w tym zalogowanych: 0, gości: 1