以下内容多个用户登录时,后一个用户的信息会将前一个用户的信息冲掉,因为servletContext是application级别,希望看的本篇博客的人注意,解决方案还未完全完成,过两天再贴。
最后用的是单点登录,CAS认证,网上已有的比较成熟的解决方案。
发送项目为项目C
public void onSetTextbox(){
Textbox texb = (Textbox)this.getFellow("texb");
SimpleSession s = (SimpleSession) Executions.getCurrent().getDesktop().getSession();
HttpSession session = (HttpSession) s.getNativeSession();
session.setAttribute("username", texb.getValue());
session.setAttribute("password", "qwert");
session.setMaxInactiveInterval(6565);
ServletContext ContextA = session.getServletContext();
ContextA.setAttribute("session", session);
//测试
HttpSession session2 =(HttpSession)ContextA.getAttribute("session");
System.out.println("IN SessionRangleServlet name : "+session2.getAttribute("username"));
System.out.println("IN SessionRangleServlet name : "+session2.getAttribute("password"));
}
接受项目为D
public void onGetTextbox() throws InterruptedException{
SimpleSession s = (SimpleSession) Executions.getCurrent().getDesktop().getSession();
HttpSession session1 = (HttpSession) s.getNativeSession();
ServletContext Context = session1.getServletContext();
ServletContext ContextA= Context.getContext("/C");
HttpSession session2 =(HttpSession)ContextA.getAttribute("session");
String message = "base传过来的user为:"+session2.getAttribute("username")+"&&&"+session2.getAttribute("password");
System.out.println(message);
Messagebox.show(message);
}
tomcat配置crossContext="true"
<Context docBase="C" path="/C" reloadable="true" crossContext="true" source="org.eclipse.jst.jee.server:C"/>
<Context docBase="D" path="/D" reloadable="true" crossContext="true" source="org.eclipse.jst.jee.server:D"/>
如果是普通的java项目session获得
HttpSession session1 =request.getSession();