public static void keepSessionLastAccessTime(StandardSessionFacade session) {
try {
long oldTime = session.getLastAccessedTime();
Field field = StandardSessionFacade.class.getDeclaredField("session");
boolean old1 = field.isAccessible();
field.setAccessible(true);
StandardSession ss = (StandardSession) field.get(session);
Field thisAT = StandardSession.class.getDeclaredField("thisAccessedTime");
boolean old2 = thisAT.isAccessible();
thisAT.setAccessible(true);
thisAT.setLong(ss, oldTime);
// 访问限制倒回
field.setAccessible(old1);
thisAT.setAccessible(old2);
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (Throwable e) {
e.printStackTrace();
}
}
部分情况需要设置:org.apache.catalina.session.StandardSession.LAST_ACCESS_AT_START为true