Interceptor Code:
@Override
Public String intercept (actioninvocation invocation) throws Exception {
Actioncontext CTX = Invocation.getinvocationcontext ();
Map session = Ctx.getsession ();
User user = (user) session.get (constants.session_user_key);
if (user = null) {
HttpServletRequest request = Servletactioncontext.getrequest ();
HttpServletResponse response = Servletactioncontext.getresponse ();
PrintWriter pw = Response.getwriter ();
String flag = "";
Interception of Ajax requests if (Request.getheader ("X-requested-with")!= null
&& Request.getheader ("X-requested-with"). Equalsignorecase (
"XMLHttpRequest")) {
Log.info ("User does not log in or logon expires, cannot access");
Response.setcharacterencoding ("Text/html;charset=utf-8");
Response.setcontenttype ("Text/html;charset=utf-8");
Flag = "9999";
Pw.write (flag);
return null;
is not an asynchronous requested intercept} else {
Response.setcharacterencoding ("Text/html;charset=utf-8");
Response.sendredirect ("/businesstest/login.jsp");
Log.info ("User does not log in or logon expires, cannot access");
return "Login";
}
}
return Invocation.invoke ();
}
JSP page code
//Login Authentication
Ext.Ajax.on (' Requestcomplete ', checkusersessionstatus, this); //All asynchronous requests will take the event
function Checkusersessionstatus (conn,response,options) {
var str = response.responsetext;
if (str = = ' 9999 ') {
alert (' The connection has timed out, please login again! ');
Window.location.href = ' login.jsp ';
}
}