Package com.controllers

Source Code of com.controllers.LoginController

package com.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.validation.BindingResult;
import java.util.Map;
import javax.validation.Valid;

import com.form.LoginForm;

@Controller
@RequestMapping("loginform.html")
public class LoginController {
  @RequestMapping(method = RequestMethod.GET)
  public String showForm(Map model) {
    LoginForm loginForm = new LoginForm();
    model.put("loginForm", loginForm);
    return "loginform";
  }

  @RequestMapping(method = RequestMethod.POST)
  public String processForm(@Valid LoginForm loginForm, BindingResult result,
      Map model) {
    String userName = "UserName";
    String password = "password";
    if (result.hasErrors()) {
      return "loginform";
    }
    loginForm = (LoginForm) model.get("loginForm");
    if (!loginForm.getUserName().equals(userName)
        || !loginForm.getPassword().equals(password)) {
      return "loginform";
    }
    model.put("loginForm", loginForm);
    return "loginsuccess";
  }

}
TOP

Related Classes of com.controllers.LoginController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.