Skip to content

Instantly share code, notes, and snippets.

@bh5k
Created June 17, 2015 18:00
Show Gist options
  • Save bh5k/fd70abcac1637d41af36 to your computer and use it in GitHub Desktop.
Save bh5k/fd70abcac1637d41af36 to your computer and use it in GitHub Desktop.
Login Controller
package com.pluralsight.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class LoginController {
// For 403 - Authentication error
@RequestMapping(value = "/403", method = RequestMethod.GET)
public String error403(ModelMap model) {
return "403";
}
// No need to add .html because in web.xml <servlet-mapping> has indicated
// to add *.html <url-pattern>
@RequestMapping(value = "/login")
public String login(ModelMap model) {
System.out.println("In the login method");
// This will tell our InternalResourceViewResolver ... /WEB-INF/jsp/
// (defined in servlet-config.xml) to lookup
// This will look for login.jsp under ... jsp folder
return "login";
}
// For login failed
@RequestMapping(value = "/loginFailed", method = RequestMethod.GET)
public String loginFailed(ModelMap model) {
System.out.println("Login Failed");
// Set the error flag so that the login.jsp <c:if
// test="${not empty error }"> will pick up
model.addAttribute("error", "true");
return "login";
}
// For logout
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String logout(ModelMap model) {
return "logout";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment