> String myuri = "/myservlet"; > myuri += ";jsessionid=" + mysessionid; // append > GetMethod get = new GetMethod(myuri); // ..etc... > > It should work.. but is it the easiest solution ?
Kamal, There's another way to go pass session id (if it is easier it is up to you to decide). ======================================================================================= HttpClient httpclient = new HttpClient(); httpclient.getState().addCookie( new Cookie(myhost, "jsessionid", mysessionid, mypath, null, false)); ======================================================================================= Where myhost - your target host (eg.: localhost) mysessionid - session id (eg.: request.getSession().getID()) mypath - your target URL (eg.: /) Be careful with the domain and path attributes of the cookie. If they are set incorrectly, HttpClient may not include the cookie with the requests as desired Have a look at the HttpState javadocs for more details http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/HttpState.html#addCookie(org.apache.commons.httpclient.Cookie) This sample may also be of help http://cvs.apache.org/viewcvs.cgi/*checkout*/jakarta-commons/httpclient/src/examples/FormLoginDemo.java?content-type=text%2Fplain&rev=1.1 Oleg -----Original Message----- From: Kamal El Bedraoui [mailto:[EMAIL PROTECTED] Sent: Friday, February 06, 2004 16:20 To: Commons HttpClient Project Subject: Re: applet to j2ee with session handling Hi, I wanted to do that but i didnt manage to get anywhere the session id as : - I have no clue how to access the cookie information from the applet (in J2SE there arent any Cookie class) - i find no other information the http headers and the url parameters... It looks like it s browser-dependant but i have been testing in several environment (linux, wds, ie nets...) and it all works the same : after a form authentication (simple html), the applet doesnt have to be authenticated if a connection is made through the normal java.net.URLConnection. The only way i see to get it is to ask the server to give it to us through java.net and request for example a JSP containing this simple tag: <%= request.getSession().getID() %> Reading in client side would be like : URLConnection conn = new URL(codebase, "/mysessionid.jsp").openConnection(); DataInputStream ois = new DataInputStream(conn.getInputStream()); String mysessionid = ois.readUTF(); After reading this info, as you said Adrian, we just have to append it to the url of the HttpMethod from httpclient. String myuri = "/myservlet"; myuri += ";jsessionid=" + mysessionid; // append GetMethod get = new GetMethod(myuri); // ..etc... It should work.. but is it the easiest solution ? ----- Original Message ----- From: "Adrian Sutton" <[EMAIL PROTECTED]> To: "Commons HttpClient Project" <[EMAIL PROTECTED]> Sent: Tuesday, February 03, 2004 10:00 PM Subject: Re: problem with applet to j2ee session handling > Hi Kamal, > > > Connecting an applet to a servlet via an http connection works fine if i use > > the java.net package using getCodeBase().openConnection(). I dont need to > > specify anywhere the session id (which i dont know how to get). > > > > But if i do the same via a GetMethod of httpclient, it doesnt work, my > > connection is redirected to the login page. I guess that I need to get the > > j2ee session id somewhere and give it (as a header ?) to the http method > > before execution... > > > > Does anyone have an idea about how it should go ? > > J2EE sessions are stored either as a parameter in the URL or as a cookie. > In this case it sounds like it's in a cookie which on IE for Windows will > automatically be sent back when using the standard URL classes. For > HttpClient and most other systems you have to manually send the cookie > yourself. You can retrieve it using javascript with document.cookie and > then pass it in to the applet as a parameter which can then be passed > through to HttpClient. > > I believe Matt Drance from Apple has polished up these instructions for me > and posted them as a FAQ somewhere on Apple's site so it's probably worth > doing a bit of a dig around there for more info. If you can't find it and > need more help I can do up some example code for you. > > > Kamal El Bedraoui > > Regards, > > Adrian Sutton. > > ---------------------------------------------- > Intencha "tomorrow's technology today" > Ph: 38478913 0422236329 > Suite 8/29 Oatland Crescent > Holland Park West 4121 > Australia QLD > www.intencha.com > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]