Java tutorial
/* * 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.ContactForm; import com.kalai.ContactFormList; import java.util.List; import javax.servlet.http.HttpSession; import org.springframework.stereotype.Controller; import org.springframework.ui.*; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.portlet.ModelAndView; /** * * @author kalaiselvan.a */ @Controller public class ContactController { @RequestMapping("/contactform") public String contactform(ModelMap map, HttpSession session) { String username = ""; try { username = (String) session.getAttribute("username"); if (username != null && username.trim().length() != 0) { map.addAttribute("Status", "input"); return "contactpage"; } else { return "index"; } } catch (Exception e) { return "PageNotFound"; } } @RequestMapping(value = "/contactpage", method = RequestMethod.POST) public String contactformStore(ModelMap map, HttpSession session, @ModelAttribute("Contactform") ContactFormList contactformlist) { String username = "", returnstring = ""; try { username = (String) session.getAttribute("username"); if (null != username && username.trim().length() != 0) { // map.addAttribute("Status", "Store"); // // List<ContactForm> contact = contactformlist.getContacts(); // map.addAttribute("listvalues", contact); System.out.println("hi" + contactformlist); System.out.println(contactformlist.getContacts()); List<ContactForm> contacts = contactformlist.getContacts(); map.addAttribute("Status", "Store"); map.addAttribute("contacts", contacts); // if (null != contacts && contacts.size() > 0) { // for (ContactForm contact : contacts) { // returnstring += contact.getName() + "--" + contact.getLname() + "--" + contact.getEmail() + "--" + contact.getPhone() + "~($#$)~"; // } // } // return returnstring; return "contactpage"; } else { return "index"; } } catch (Exception e) { return "PageNotFound"; } } }