@Controller
public class LoginController {
@RequestMapping(value = "showLogin", method = RequestMethod.GET)
public ModelAndView showLogin(HttpServletRequest request, HttpSession session) {
return new ModelAndView("login");
}
@RequestMapping(value = "login", method = RequestMethod.POST)
public String login(HttpServletRequest request, HttpSession session) {
String page = "login";
String loginId = request.getParameter("loginId");
String password = request.getParameter("password");
// HttpSession session = request.getSession();
session.setAttribute("USERNAME", loginId);
if(loginId.equals("admin") && password.equals("admin")){
session.setAttribute("loginId", "admin");
session.setAttribute("userName", "admin");
session.setAttribute("userDetails", "System Administrator");
session.setAttribute("USERNAME", "admin");
page = "home";
return page;
}
@RequestMapping(value = "projdet", method = RequestMethod.GET)
public String project(
@ModelAttribute("projMaster") ProjectMaster projMaster,
Model model, HttpServletRequest request, HttpSession session) {
List<ProjectMaster> allProjectlist =getMasterDaoService().getAllProjList();
model.addAttribute("Projlist", allProjectlist);
String page = "project";
return page;
}
Session only works one time spring mvc,once login returns home page but from home to next screen no user details and session not found in any other controller
I have a few suggestions:
projdet
". List<ProjectMaster> allProjectlist =getMasterDaoService().getAllProjList(); model.addAttribute("Projlist", allProjectlist);
List<ProjectMaster> allProjectlist =getMasterDaoService().getAllProjList(); model.addAttribute("Projlist", allProjectlist);
. Check the session
variable thoroughly to see if it has the attributes you set on login logout
? While these may not point out the exact solution, it may help you figure out the issue. From what you have presented in the question, there is no evidence of anything wrong in the code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.