com.kalai.controller.HomeController.java Source code

Java tutorial

Introduction

Here is the source code for com.kalai.controller.HomeController.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kalai.controller;

import com.kalai.loginusers;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 *
 * @author kalaiselvan.a
 */
@Controller
public class HomeController {

    @RequestMapping(value = "/home")
    public String home(HttpSession session, ModelMap map) {
        String username = "";
        try {
            username = (String) session.getAttribute("username");
            if (!username.equals("") && username.trim().length() != 0) {
                map.addAttribute("msg", "Hai this is home page using Spring and Hibernate=====" + username);
                return "Home";
            } else {
                return "PageNotFound";
            }
        } catch (Exception ex) {
            return "PageNotFound";
        }

    }

    @RequestMapping(value = "/home", method = RequestMethod.POST)
    public String homepage(ModelMap map, @ModelAttribute("loginform") loginusers loginusers, HttpSession session) {
        session.setAttribute("username", loginusers.getEmail());
        session.setAttribute("password", loginusers.getPassword());
        String username = (String) session.getAttribute("username");
        if (!username.equals("") && username.trim().length() != 0) {
            map.addAttribute("msg", "Hai this is home page using Spring and Hibernate" + loginusers.getEmail());
            return "Home";
        } else {
            return "PageNotFound";
        }
    }
}