以下内容多个用户登录时,后一个用户的信息会将前一个用户的信息冲掉,因为servletContext是application级别,希望看的本篇博客的人注意,解决方案还未完全完成,过两天再贴。
最后用的是单点登录,CAS认证,网上已有的比较成熟的解决方案。
发送项目为项目C
[java] view plaincopy
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
[java] view plaincopy
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"
[html] view plaincopy
<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获得
[java] view plaincopy
HttpSession session1 =request.getSession();
网站建设就找金功呈,网址:http://www.songhu9.com.cn,通过互谅网整理有用信息,希望对广大网民有帮助!

- 深圳市一键一家网络科技有限公司官方网址:http://www.songhu9.com.cn
- QQ:316675593,电话号码:19807655856
- 业务范围:公司网站建设、管理软件研发、软件网站二次开发、400电话、电商平台研发、公众号研发!
- 免责申明:本站内容均来源于网络,版权归原创所有,如有任何版权方面的问题,请与我们联系处理!