One of a controller's action
@RequestMapping("/user/login")
public String loginPage(String errorMessage, Model model) {
model.addAttribute("errorMessage", errorMessage);
return "/view/loginPage";
}
A snippet of viewPage.jsp
<div id="alertError">Failed to get data because : ${errorMessage}</div>
A snipper of my interceptor
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
HttpSession session = request.getSession();
User user = (User)session.getAttribute("user")
if ( user == null ) {
response.sendRedirect("/user/login.do");
}
}
Okay time to explain.
The interceptor checks a session and redirects to the signin page if session is null. I want to display a message your session was expired. Please sign in
after the complete redirection.
But in the interceptor, I can't find any way to pass the message to the loginPage
action. How can I do that?
FYI, Directly calling the loginPage
method is not an answer for me.
You can pass your message as query parameter.
And in the controller side it can be retrieved as,