您不想在webapp的生存期内拥有同一servlet的不同 实例
。通常的做法是使用
HttpSession来区分客户端。您需要将
HttpSession#getId()as参数传递给相关的applet:
<param name="jsessionid" value="${pageContext.session.id}">然后,在Applet中按如下所示连接Servlet:
String jsessionid = getParameter("jsessionid");URL servlet = new URL(getCodebase(), "servleturl;jsessionid=" + jsessionid);URLConnection connection = servlet.openConnection();// ...这里servleturl
显然应该与Servlet的url-pattern
在web.xml
。您也可以cookie
使用设置请求标头URLConnection.setRequestProperty()
。
最后,在Servlet中,要获取和存储客户端特定的数据,请执行以下操作:
// Store:request.getSession().setAttribute("data", data);// Get:Data data = (Data) request.getSession().getAttribute("data");希望这可以帮助。



