一个tomcat下跨应用获取application和session属性值
程序员文章站
2024-02-28 21:14:22
...
跨应用获取application和session属性值
online应用
application.setAttribute("online_uname_str",getOnlineUserNameString(useronline));
session.setAttribute("online");
test应用
ServletContext ac=application.getContext("/online");
String userStr=String.valueOf(ac.getAttribute("onlineuser"));
ServletContext onlineContex=this.getServletConfig().getServletContext().getContext("/online");
if(onlineContex==null){
out.print("onlineContex=null");
return;
}
HttpSession onlineSession=(HttpSession)onlineContex.getAttribute("online");
if(onlineSession.getAttribute("hello")!=null){
out.print(onlineSession.getAttribute("hello"));
}
另外注意online的数据源配置Context里需加上 crossContext="true"属性