您好我正在使用以下代码段来获取门户网站服务器中的会话一旦设置但我得到的结果为null
public void viewSession(WebAppAccess webAppAccess) throws PortletException,
IOException {
String sessionValue="userDefinedValue";
try {
PortletRequest portletRequest = (PortletRequest) webAppAccess
.getHttpServletRequest().getAttribute(
Constants.PORTLET_REQUEST);
PortletSession session = portletRequest.getPortletSession();
session.setAttribute("application",
sessionValue, PortletSession.APPLICATION_SCOPE);
log.Info("AFTER SET SESSION VALUE:----"
+ session.getAttribute("application"));
}
catch (Exception e) {
log.Error("error is:---", e);
}
}
但是,结果我得到空值
设置会话后值:---- null
请给出解决方案
答案 0 :(得分:0)
尝试使用范围PortletSession.APPLICATION_SCOPE
:
session.getAttribute("application", PortletSession.APPLICATION_SCOPE);