Instantly share code, notes, and snippets.

Embed
What would you like to do?
Spring MVC login
@Controller
@RequestMapping("/")
public class CorrectLogin {
@RequestMapping(method = RequestMethod.POST, value = "loginForm")
public String login(@ModelAttribute LoginCredentials loginCredentials) {
SessionDTO sessionDTO = usersService.login(loginCredentials);
if (sessionDTO == null) {
return "/login";
}
return "redirect:index.html"; // this is how you send send a redirect response !
}
}
@Controller
@RequestMapping("/")
public class Login {
@RequestMapping(method = RequestMethod.POST, value = "loginForm")
public String login(@ModelAttribute LoginCredentials loginCredentials) {
SessionDTO sessionDTO = usersService.login(loginCredentials);
if (sessionDTO == null) {
return "/login";
}
return "index.html"; //forwards to index.html !!!!
}
}
/**
* Created by adelin.ghanayem@gmail.com
*/
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.tgallery.web")
public class WebConfiguration extends WebMvcConfigurerAdapter {
@Autowired
private SessionsService sessionsService;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
//index.html is contained in /resources/ folder in root directory!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment