在你的CSR_menu.jsp上设置一个form 提交到QueryRingingServletString url = "http://localhost:8080/servlet/QueryRingingServlet"; URLConnection connect= new URL(url).openConnection(); connect.connect(); DataInputStream in = new DataInputStream(connect.getInputStream());这种做法很怪哦,特别是servlet里面,新开了一个session,又不知道做什么用
String url = "http://localhost:8080/servlet/QueryRingingServlet";
if (thisPhone == null){
thisPhone = new Phone(thisCCfgInfo);
thisPhone.initialize();
session.setAttribut("PHONE",thisPone);
}
request.getRequestDispatcher(response.encodeURL("/jsp/menu/CSR_menu.jsp")).forward(request,response);
}
恩,看不明白!!
第一点:你的thisPone是什么类型啊?
第二点:你的Phone是定义的类吗?
第三点:你的thisPhone == null又是什么意思?
2、Phone是定义的类。
3、thisPhone==null 的意思是:如果第一次thisPhone肯定是空的,这个时候就new 一个Phone.不知道我这么说你明白否?
那我要怎么做才能是同一用户呢?
对
换一种做法吧
提交到QueryRingingServletString url = "http://localhost:8080/servlet/QueryRingingServlet";
URLConnection connect= new URL(url).openConnection();
connect.connect();
DataInputStream in = new DataInputStream(connect.getInputStream());这种做法很怪哦,特别是servlet里面,新开了一个session,又不知道做什么用
而且我的submit要每隔一段时间(比如1秒)提交一次,目的是去服务器查询状态
<body onload="form.submit()">
<FORM name="form" action="xxx"></FORM>
...
window.close
...
</body>
也就是页面load的时候自动提交一个form,然后close掉或者你可以在你的源码这样写,
String url = "http://localhost:8080/servlet/QueryRingingServlet";
StringBuffer sbf = new StringBuffer();
sbf.append(url).append("?phone=").append(session.getAttribute("PHONE").toString());
总之可以把它当作query再传过去
不过重要的是例如%& 之类的符号都要重新encode,例如" "->"+",可调用URLEncoder.encode()方法
我猜想你是在jsp写这段代码的,在这个jsp还可以取到phone值的方法还是很多的
HttpSession session = request.getSession(true);
-》
HttpSession session = request.getSession(false);
试试。。如果不行
在QueryRingingServlet中打印出session id
System.out.println(session.getId());
在LoginCTIServlet中也打印出session id
System.out.println(session.getId());
看看这两个id是不是同一个,如果不是,那么你的问题所在就是
由不同session所照成的,建议楼主换一种方法。