2 Replies Latest reply: Mar 28, 2012 11:44 AM by 698529 RSS

    Reusing the sessionid between web and swing

      I have a servlet that is called from an web application and creates a Session. The sessionId of this session is passed to a swing application using the approach below:

      Re: Trasnfering data from a JNLP call to swing dynamically

      From my swing application I want to connect to the same servlet passing the sessionid. The purpose is to work with the same session created before.

      It's not working. I'm calling the servlet from the swing application using the following url:


      Is it possible ?

      Thanks. Mauro.
        • 1. Re: Reusing the sessionid between web and swing
          Yes, but you have to use the correct method of storing the sessionId. There are two possibilities depending on how the server is configured:

          cookie based (the default) - the sessionId is kept in a cookie which needs to be transmitted with each request made
          url rewriting - the sessionId is encoded into the url like in the example you link to

          Most likely you should be using the cookie approach. the Apache HttpClient API makes that quite easy to do, I suggest you investigate it.
          • 2. Re: Reusing the sessionid between web and swing
            Thanks for reply.

            I'm using url rewriting approach and this works fine between different calls from swing to servlet. I mean, the sessionid is created by the first call from swing to servlet and the session is maintained between the following calls.

            The servlet appends in the header of the response the sessionid :

            httpResp.addHeader("jsessionid", session.getId());

            And the client rewrites the url like that

            String sessionId = conn.getHeaderField("jsessionid");
            url = new URL(strURL + ";jsessionid=" + sessionId);

            Am I doing it right? Why it doesnt work when the sessionid is created by a web call.

            If I don't make it work I would try the cookie approach using HttpClient as you suggested.


            Edited by: Mauro Flores on 28/03/2012 09:43

            Edited by: Mauro Flores on 28/03/2012 09:43