You don't want to have different instances of the same servlet in webapp's lifetime. The normal practice is to use the HttpSession
to distinguish between clients. You need to pass the HttpSession#getId()
as parameter to the applet in question:
<param name="jsessionid" value="${pageContext.session.id}">
Then, in the Applet connect the Servlet as follows:
String jsessionid = getParameter("jsessionid");
URL servlet = new URL(getCodeBase(), "servleturl;jsessionid=" + jsessionid);
URLConnection connection = servlet.openConnection();
// ...
Here servleturl
obviously should match servlet's url-pattern
in web.xml
. You can alternatively also set a Cookie
request header using URLConnection.setRequestProperty()
.
Finally, in the Servlet, to get and store client specific data, do as follows:
// Store:
request.getSession().setAttribute("data", data);
// Get:
Data data = (Data) request.getSession().getAttribute("data");
Hope this helps.