Method One: Use Servlet-api
@Controllerpublic class Managercontroller {@Resourceprivate managerservice Managerserviceimpl; @RequestMapping (value = "Manager/login.do", method = requestmethod.get) public modelandview login (Managermodel managermodel,httpsession HttpSession) {Managermodel manager = Managerserviceimpl.getmanager (Managermodel), if (manager!=null) { Manager.setpassword (""); Httpsession.setattribute ("manager", manager); return new Modelandview ("New Redirectview". /admin/main.jsp "));} Else{return New Modelandview (New Redirectview ("... /admin/login.jsp "));}} @RequestMapping (value = "Manager/logout.do", method = requestmethod.get) public String logout (HttpSession HttpSession) { Httpsession.getattribute ("Manager"); Return "Success"; }}
Method Two: Use Sessionattributes
@Controller @sessionattributes ("manager") public class Managercontroller {@Resourceprivate ManagerService Managerserviceimpl; @RequestMapping (value = "Manager/login.do", method = requestmethod.get) public Modelandview Login (Managermodel Managermodel,modelmap model) {Managermodel manager = Managerserviceimpl.getmanager (Managermodel); if (manager!=null) {Manager.setpassword (""); Model.addattribute ("manager", manager); return new Modelandview (new Redirectview (".. /admin/main.jsp "));} Else{return New Modelandview (New Redirectview ("... /admin/login.jsp "));}} @RequestMapping (value = "Manager/logout.do", method = requestmethod.get) public String logout (@ModelAttribute ("Manager ") Managermodel Managermodel) {return" Success ";}}
Two methods of SPRINGMVC access session