The solution we are discussing is built using a servlet
Let us see in detail.
Given a session id, let us try to lookup the session
Step - 1
Create a new servlet
public class LookedUpSessionActor extends HttpServlet implements Servlet{
protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
doPost(arg0, arg1);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession(false);
if(session != null){
System.err.println(session.getAttribute(“Test_Message”));
}else{
System.err.println(“Session already invalidated”);
}
response.setContentType("text/html;charset=UTF-8");
response.getOutputStream().println("Successful");
}
}
Give the servlet
Also, for this example, let us assume that our servername is myserver and application name is myapp, so the url of the servlet
http://myserver/myapp/LookedUpSessionActor
Step – 2
Write the class and a method which does the lookup of the session
public class SessionLookupHelper {
public void initiateActionOnSession(String sessionId) {
String urlString = "http://myserver/myapp/LookedUpSessionActor";
try {
URL url = new URL(urlString);
HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
urlc.setRequestProperty("Cookie", "JSESSIONID="+sessionId);
urlc.setDoOutput(true);
urlc.getContent();
urlc.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Basically this class will make a URL Connection to the servlet
You are all set. Whenever you want to operate on the other session