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/");
}