-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Login Action Class
===============
@Controller
@RequestMapping("/logon.htm")
@SessionAttributes({ "clubNumberList", "user", "club" })
public class LoginFormController {
......
......
@RequestMapping(method = RequestMethod.POST)
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, @ModelAttribute("user") User userParam, ModelMap modelMap) throws ServletException, Exception {
User user = setUserInfo(request, (User) userParam);
final HttpSession session = request.getSession(true);
UserAccessStatus accessStatus = loginHelper.getAuthorization(user);
if (accessStatus.isAuthorized()) {
List<String> storeNumberList = loginHelper.getClubNumberList();
session.setAttribute("clubNumberList", storeNumberList);
session.setAttribute("user", userParam);
session.setAttribute("club",loginHelper.getClub(Integer.parseInt(user.getClubNumber())));
DefaultViewBean pageBean = new DefaultViewBean();
pageBean.setUser(user);
//loginRedirectView = new ModelAndView("main");
loginRedirectView = new ModelAndView("main", "command", pageBean);
return loginRedirectView;
} else {
status = accessStatus.getErrorMessage();
user.setCtHeaderMessage(status);
user.setClubNumber(null);
session.setAttribute("AuthenticationFailMsg", user.getCtHeaderMessage());
return loginRedirectView = new ModelAndView("logon");
}
}
Once I login, i will get a home page where i type member info and click 'GO' submit button. When I click GO button, am getting the errors which i mentioned in my last post.
Hi,
Most probably you are trying to retrieving user from session while it is not there please debug this thing properly.
Shwetha Jagadish
Greenhorn
Joined: Mar 28, 2011
Posts: 11
posted
0
The code absolutely works fine if i don't configure SessionFilter to my application but if i put SessionFilter Code and after session gets expired and then if i do some action(POST request), am getting exception
org.springframework.web.HttpSessionRequiredException: Session attribute 'user' required - not found in session.
/**
*
* This class works for Session Time out. If the session is timed-out and if there is some action,
* the flow will navigate to login page.
*/
public class SessionFilter implements Filter {
/* (non-Javadoc)
* @see javax.servlet.Filter#destroy()
*/
@Override
public void destroy() {
// TODO Auto-generated method stub
}
}
Shwetha Jagadish
Greenhorn
Joined: Mar 28, 2011
Posts: 11
posted
0
After putting below entry in web.xml, the problem has been resolved. It will be great pleasure if some one suggest me the below solution is correct or not.
This might solves the problem but it isn't a proper way as you are hiding the error and then redirecting to your main page. However this error will still be present in the web server console.
To solve this follow these steps.
1. Before going to the server you must have this has parameter @ModelAttribute ("User")User user to the Controller Class's Method
and this Declaration
@SessionAttributes("User") above Controller class
means it will check User named attribute in the session.
I'm new to Spring and i am doing session management in this way. Please rectify me if i am wrong and provide the solution.
Whenever posting code. PLEASE use the CODE tags so that we can read the code. There is a button labeled Code. Just click it and it will add Code tags, then you can past your code in between those tags.