我在访问应该已经注入Interceptor的应用程序映射时遇到了NullPointerException
,因为我实现了ApplicationAware
接口。如何在自定义拦截器中使用Application范围变量?
public String intercept(ActionInvocation ai) throws Exception {
String result = "expire";
app.put("login_msg", "Session Expired");
Map session = ai.getInvocationContext().getSession();
try {
if ((session != null && session.get("login").toString().equalsIgnoreCase("true")) || !app.get("db_name").toString().equals("")) {
log.info("login hai");
app.put("login_msg", "");
result = ai.invoke();
} else {
log.error(" LOGIN EXPIRED ");
}
} catch (NullPointerException npe) {
log.error("Error : " + npe);
}
log.info("Interceptor Result : " + result);
return result;
}
@Override
public void setApplication(Map<String, Object> map) {
app = map;
}
你(试图)明确地说“会话”,如在登录会话中的字符串,显式称为“应用程序”应该是一个巨大的红色警告标志,可能在思维过程中出现了问题。 –
@HarshdeepSingh这已经是另一个问题了。 –